By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Java user class directory not found

P: 1
I have a problem with Java finding my custom class directory. I have searched the forums and tried everything, but nothing seems to work. The <javapgm>.java compiled cleanly and created <javapgm>.class. Error message is:

Warning: java.lang.ClassNotFoundException: javapgm

Versions of software:

Apache 2.0.59(Win32)
PHP 4.4.4
Java 1.5.0_01
Windows 2000 5.0

In my application, PHP displays a screen, data is entered, and the above error occurs. I swapped out my custom Java class for an example I found on the internet:

$system = new Java("java.lang.System");
print "Java version=".$system->getProperty("java.version")." <br>\n";
print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";
print "OS=".$system->getProperty("os.name")." ".
$system->getProperty("os.version")." on ".
$system->getProperty("os.arch")." <br>\n";

$formatter = new Java("java.text.SimpleDateFormat","EEEE,
MMMM dd, yyyy 'at' h:mm:ss a zzzz");
print $formatter->format(new Java("java.util.Date"))."\n";

and it properly works and displays:

Java version=1.5.0_01
Java vendor=Sun Microsystems Inc.
OS=Windows 2000 5.0 on x86
Friday, July 20, 2007 at 9:33:06 AM GMT-07:00

I found the documentation regarding the difference between accessing user classes, java extension classes and bootstrap classes, then added my custom class directory (user class) to the php.ini file after java.class.path=:

java.class.path= "c:\php\extensions\php_java.jar; c:\www\slfsrvmar\javaclasses"
java.library.path = "c:\php\extensions; "c:\jdk\jdk1.5.0_01\jre\lib"
java.home = "c:\jdk\jdk1.5.0_01\bin"
java.library = "c:\jdk\jdk1.5.0_01\jre\bin\client\jvm.dll"

I tried swapping the order of the two directories in java.class.path. My custom class still did not work and neither did the getPropriety test, above. The second directory in the concatenation does not seem to be recognized (yes, it's typed correctly). Note, that Apache was stopped/started each time when php.ini was changed and a new browser window was also opened after each Apache cycling.

I then found a java method to change the directory thinking that might be the solution:

$system = new Java("java.lang.System");
print "java.class.path BEFORE=".$system->getProperty("java.class.path")." <br>\n";
$system->setProperty("java.class.path", "c:\\www\\slfsrvmar\\javaclasses");
print "AFTER path change=".$system->getProperty("java.class.path")." <br>\n";

which produced:

java.class.path BEFORE=c:\php\extensions\php_java.jar; c:\www\slfsrvmar\javaclasses AFTER path change=c:\www\slfsrvmar\javaclasses

My class was still not found.

Then modified WINNT environment variable CLASSPATH and added c:\www\slfsrvmar\javaclasses. Rebooted and still the same problem.

I am totally mystified as to what to do next. The PHP/Java interface seems to be working or the Java version and todayís date display would not function.

Any help will be most appreciated. Iím quite new to Java.

Thanks, MAR
Jul 20 '07 #1
Share this Question
Share on Google+
1 Reply


prometheuzz
Expert 100+
P: 197
Well I have no experience with PHP, but you're warm about the CLASSPATH there: if a class file compiles but doen't run (throws a NoClassDefFoundError) then there's something wrong with the CLASSPATH.

Just a shot in the dark, but maybe that space is messing things up?
Expand|Select|Wrap|Line Numbers
  1. java.class.path= "c:\php\extensions\php_java.jar; c:\www\slfsrvmar\javaclasses"
  2.                                                  ^
  3.                                                  !
Jul 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.