2

I've followed this tutorial http://www.dsl.uow.edu.au/~sk33/php5java.htm, but at last when I tried this

<?php

java_require('http://localhost/test/HelloWorld.jar');
$myObj = new Java('HelloWorld');

// display Hello World
echo (String) $myObj->getHelloWorld();


?>

I got this exception

PHP Fatal error: Uncaught [o(Exception):"java.lang.Exception: CreateInstance failed:new HelloWorld. Cause: java.lang.ClassNotFoundException: Could not find HelloWorld in java_require() path. Please check the path and the SEL and File permissions. Responsible VM: 1.5.0_14@http://java.sun.com/" at:#-10 php java.bridge.DynamicJavaBridgeClassLoader.loadClass(DynamicJavaBridgeClassLoader.java:293)

1
  • Is it possible to specify a filesystem path to HelloWorld.jar instead of a URL? Commented Aug 6, 2012 at 13:41

2 Answers 2

2

The tutorial you're following is 5 years old and, according to the FAQ, java_require() is deprecated:

Why has java_require() been deprecated?

Because Java doesn't have a module system.

For example a library "lucene-2.3.1.jar" required by application B, cannot be loaded if an older version of the library, required by application A, is already cached. An attempt to link the library anyway will cause "NoClassDefFound" or "NoSuchMethod" errors at runtime. Or some procedures may throw checked exceptions even though they haven't declared them.

To protect PHP developers from Java's "jar hell", I have removed the dynamic class loading mechanism from PHP/Java Bridge version 6.0; java_require() issues a warning.

A proper Java module system must use special Java VM hooks, which don't exist until now.

How do I load Java libraries?

You should link your Java application as described in the Java standalone or Java webapps documents.

Sign up to request clarification or add additional context in comments.

Comments

1

The error indicates that the HelloWorld class wasn't found.

Verify that the file is really located at the address you used for java_require. If it is, check and make sure the code in the file is exactly as described in the tutorial.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.