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

Calling Java Classes on Server

P: n/a
I have the Java JVM installes on my server.

I uncommented
extension=php_java.dll
in php.ini

I uncommented and proerpyl filled out the [java] section in php.ini:
[Java]
java.class.path ="C:\InstantRails\php\extensions\php_java.jar;C:\J avaSources\MyStuff"
java.home = "C:\Program Files\Java\jdk1.5.0_10;C:\Program Files\Java\jre1.5.0_10\lib"
java.library = "C:\Program Files\Java\jdk1.5.0_10\jre\bin\server\jvm.dll"
java.library.path = "C:\InstantRails\php\extensions\;C:\Program Files\Java\jdk1.5.0_10\jre\lib"
I created a little php file to test it all out:
<?php
$system = new Java("java.lang.System");
echo 'Java version installed = ' . $system->getProperty('java.version') . "<br />";
echo 'Java vendor = ' . $system->getProperty('java.vendor') . "<br />";
echo 'Running on server = ' . $system->getProperty('os.name') . "<br />";
$des = new java("DES","xray");
echo $des . "<br />";
$x="hello";
echo $x . ' = ' . $des->encrypt($x);
?>

Which outputs as:

Java version installed = 1.5.0_10
Java vendor = Sun Microsystems Inc.
Running on server = Windows XP
Object
hello =

Note that I have a class file C:\JavaSources\MyStuff\DES.class with an encrypt(String) function. Everything works fine, even when I echo out $des it shows as Object.

However, my last line does not output the encrypt function. Can anyone tell me why?

Also, if I go to run the php script a subsequent time, I get:

Fatal error: Unable to create Java Virtual Machine in c:\instantrails\www\javafromphp.php on line 2

unless I either reboot the computer or restart my apache web server under which php is running. Anyone ever call a java class from php? -R. Vince
Jun 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rik
On Sat, 16 Jun 2007 14:06:51 +0200, Janna <mi***********@hotmail.com
wrote:
I have the Java JVM installes on my server.
I created a little php file to test it all out:
<?php
$des = new java("DES","xray");
echo $des . "<br />";
echo $x . ' = ' . $des->encrypt($x);
?>

Which outputs as:

Object

Note that I have a class file C:\JavaSources\MyStuff\DES.class with an
encrypt(String) function. Everything works fine, even when I echo out
$des it shows as Object.

However, my last line does not output the encrypt function. Can anyone
tell me why?
To know what $des actually is:
1. var_dump($des);
2. print_r(get_class_methods(get_class($des)));

Can't help you with the Java bit, never used it.
--
Rik Wasmus
Jun 16 '07 #2

P: n/a
"Janna" <mi***********@hotmail.comwrote in
news:46***********************@roadrunner.com:
I have the Java JVM installes on my server.

I uncommented
extension=php_java.dll
in php.ini

I uncommented and proerpyl filled out the [java] section in php.ini:
[Java]
java.class.path
="C:\InstantRails\php\extensions\php_java.jar;C:\J avaSources\MyStuff"
java.home = "C:\Program Files\Java\jdk1.5.0_10;C:\Program
Files\Java\jre1.5.0_10\lib" java.library = "C:\Program
Files\Java\jdk1.5.0_10\jre\bin\server\jvm.dll" java.library.path =
"C:\InstantRails\php\extensions\;C:\Program
Files\Java\jdk1.5.0_10\jre\lib"
Hi Janna

I've used Java with PHP before and it was a doozy to get going. To sum
it up, you have to make sure that the user under which Apache is running
has access to Java... or all users.

What I did was add the following to "/etc/profile":

pathmunge /usr/java/j2sdk1.4.2_14/bin
pathmunge /usr/java/j2sdk1.4.2_14/jre/bin

**************

Whoa whoa, wait, i just realized you are on Windows. I will leave the
stuff above as reference for people having issues with Linux!

For Windows, try the equivalent (from
http://java.sun.com/j2se/1.4.2/install-windows.html )

.. Update the PATH variable (Optional)

You can run the Java 2 SDK without setting the PATH variable, or you
can optionally set it as a convenience.

Should I set the PATH variable?
Set the PATH variable if you want to be able to conveniently run the
Java 2 SDK executables (javac.exe, java.exe, javadoc.exe, etc.) from
any directory without having to type the full path of the command.
If you don't set the PATH variable, you need to specify the full
path to the executable every time you run it, such as:

C:\j2sdk1.4.2_<version>\bin\javac MyClass.java

It's useful to set the PATH permanently so it will persist after
rebooting.

How do I set the PATH permanently?
To set the PATH permanently, add the full path of the
j2sdk1.4.2_<version>\bin directory to the PATH variable. Typically
this full path looks something like C:\j2sdk1.4.2_<version>\bin. Set
the PATH as follows, according to whether you are on Microsoft
Windows NT or 98/2000/ME.

Microsoft Windows NT, 2000, and XP - To set the PATH permanently:

1. Choose Start, Settings, Control Panel, and double-click
System. On Microsoft Windows NT, select the Environment tab; on
Microsoft Windows 2000 select the Advanced tab and then
Environment Variables. Look for "Path" in the User Variables and
System Variables. If you're not sure where to add the path, add
it to the right end of the "Path" in the User Variables. A
typical value for PATH is:

C:\j2sdk1.4.2_<version>\bin

Capitalization doesn't matter. Click "Set", "OK" or "Apply".

The PATH can be a series of directories separated by
semi-colons (;). Microsoft Windows looks for programs in the
PATH directories in order, from left to right. You should only
have one bin directory for a Java SDK in the path at a time
(those following the first are ignored), so if one is already
present, you can update it to j2sdk1.4.2_<version>\bin.

2. The new path takes effect in each new Command Prompt window
you open after setting the PATH variable.
here's another reference:
http://ccism.pc.athabascau.ca/html/vhd/javapath.xml#xp

Good luck!!!!
Jun 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.