Calling Java Classes on Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Janna

    Calling Java Classes on Server

    I have the Java JVM installes on my server.

    I uncommented
    extension=php_j ava.dll
    in php.ini

    I uncommented and proerpyl filled out the [java] section in php.ini:
    [Java]
    java.class.path ="C:\InstantRai ls\php\extensio ns\php_java.jar ;C:\JavaSources \MyStuff"
    java.home = "C:\Program Files\Java\jdk1 .5.0_10;C:\Prog ram Files\Java\jre1 .5.0_10\lib"
    java.library = "C:\Program Files\Java\jdk1 .5.0_10\jre\bin \server\jvm.dll "
    java.library.pa th = "C:\InstantRail s\php\extension s\;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('j ava.version') . "<br />";
    echo 'Java vendor = ' . $system->getProperty('j ava.vendor') . "<br />";
    echo 'Running on server = ' . $system->getProperty('o s.name') . "<br />";
    $des = new java("DES","xra y");
    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.cla ss 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\javafromph p.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
  • Rik

    #2
    Re: Calling Java Classes on Server

    On Sat, 16 Jun 2007 14:06:51 +0200, Janna <mistressjanna@ 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","xra y");
    echo $des . "<br />";
    echo $x . ' = ' . $des->encrypt($x);
    ?>
    >
    Which outputs as:
    >
    Object
    >
    Note that I have a class file C:\JavaSources\ MyStuff\DES.cla ss 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_cla ss_methods(get_ class($des)));

    Can't help you with the Java bit, never used it.
    --
    Rik Wasmus

    Comment

    • Good Man

      #3
      Re: Calling Java Classes on Server

      "Janna" <mistressjanna@ hotmail.comwrot e in
      news:4673d25f$0 $16602$4c368faf @roadrunner.com :
      I have the Java JVM installes on my server.
      >
      I uncommented
      extension=php_j ava.dll
      in php.ini
      >
      I uncommented and proerpyl filled out the [java] section in php.ini:
      [Java]
      java.class.path
      ="C:\InstantRai ls\php\extensio ns\php_java.jar ;C:\JavaSources \MyStuff"
      java.home = "C:\Program Files\Java\jdk1 .5.0_10;C:\Prog ram
      Files\Java\jre1 .5.0_10\lib" java.library = "C:\Program
      Files\Java\jdk1 .5.0_10\jre\bin \server\jvm.dll " java.library.pa th =
      "C:\InstantRail s\php\extension s\;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\ja vac 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_<ver sion>\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_<ver sion>\bin.

      2. The new path takes effect in each new Command Prompt window
      you open after setting the PATH variable.


      here's another reference:


      Good luck!!!!

      Comment

      Working...