Practical
Embedded Java

Java paths


A practical engineering approach to using embedded Java in real-world applications.


...



There seems to be quite a bit of confusion about just what happens when you invoke the Java launcher (java.exe) on a PC. I'm not immune to that too, and this page is an attempt to think about the question and solicit input from those of you 'out there' who have a more complete understanding of this.

Part of the point of this exercise is to prove that you do _not_ need to include the javaxcomm files in the JRE folders of your JDSK, provided you follow the instructions which come with the javaxcomm installation files (these are the same instructions given on this web site). If you think you need to copy javaxcomm files into a JRE folder, then something else in your classpath is not properly configured. Fix that problem, since it may come back to haunt you with other Java tool libraries. Don't go copying files into other JRE folders on your system. Copying important files into multiple places makes it too hard to maintain and upgrade. You want to have important system and library files located in one standardized place, and you want all your office PCs to be set up identically.


C:\WINDOWS\SYSTEM32 typically contains Java runtime (JRE) executables

C:\WINDOWS\SYSTEM32 will contain JRE files such as java.exe, javaw.exe, and so on, if you have every installed the JRE on your PC, or if you have installed programs which automatically install the JRE. In most Windows systems, this C:\WINDOWS\SYSTEM32 folder is, by default, the first entry in the System PATH variable. Type "set" at a command window to find out your PC's path. Here's mine:

Path=c:\windows\system32;c:\windows;c:\windows\system32\wbem;d:\j2sdk14\bin;d:\apache-ant-1.5.4\bin;[other entries snipped off]

What this means is that any java programs will, by default, find these java runtime files in c:\windows\system32; before they find the java runtime I intend them to use: d:\j2sdk14\bin; So what can you do about this? You can put the Java runtime first in the path, but then every Windows program search which uses the path will also start there. Some Java programs let you specify the path to the runtime support which you wish to use -- this is a nice feature and won't affect any other programs. There might be some way to override this in the Windows registry, at least on a per-program basis. If anyone knows about other solutions to this, please email us. You could also update the c:\windows\system32 JRE files to the version which you wish to use by default. I'm currently not certain of the best way to do this.


Some experimentation with "java.exe" invocation
If you want to invoke a specific Java launcher and JVM, you can use an explicit path to that "java.exe" of course. For example, on my PC as I showed you, there are about eight "java.exe" files in various copies of the JRE, multiple JSDKs, and so on. So if I want to invoke the JDK 1.4.1 java explicitly on BlackBox (since I have the javaxcomm support installed in my JDK 1.4.1 but not in every JRE on my system):

Temporarily (for this DOS command window session) add the BlackBox JAR to my classpath. Note that this only works if this is really where the BlackBox JAR is...

set CLASSPATH=%JAVA_LIB%\commapi\samples\BlackBox\BlackBox.jar;%CLASSPATH%

Now invoke a specific java launcher:

D:\j2sdk14\bin\java BlackBox

In my case I used the verbose option to see if this really makes a difference in which java.exe gets used.

In the "whatever java.exe is in the registry" case:

D:\Docs>java -verbose BlackBox
[Opened C:\Program Files\Java\j2re1.4.1_01\lib\rt.jar]
[Opened C:\Program Files\Java\j2re1.4.1_01\lib\sunrsasign.jar]
[Opened C:\Program Files\Java\j2re1.4.1_01\lib\jsse.jar]
[Opened C:\Program Files\Java\j2re1.4.1_01\lib\jce.jar]
[Opened C:\Program Files\Java\j2re1.4.1_01\lib\charsets.jar]
[Loaded java.lang.Object from C:\Program Files\Java\j2re1.4.1_01\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\j2re1.4.1_01\lib\rt.jar]
.... and so on

Now the explicit java invocation:

D:\Docs>D:\j2sdk14\bin\java -verbose BlackBox
[Opened D:\j2sdk14\jre\lib\rt.jar]
[Opened D:\j2sdk14\jre\lib\sunrsasign.jar]
[Opened D:\j2sdk14\jre\lib\jsse.jar]
[Opened D:\j2sdk14\jre\lib\jce.jar]
[Opened D:\j2sdk14\jre\lib\charsets.jar]
[Loaded java.lang.Object from D:\j2sdk14\jre\lib\rt.jar]
[Loaded java.io.Serializable from D:\j2sdk14\jre\lib\rt.jar]

So, the explicit invocation does make a difference.

Just for fun I tried this, with the default path being the location of the java.exe I want:

D:\j2sdk14\bin>java -verbose BlackBox
[Opened D:\j2sdk14\jre\lib\rt.jar]
[Opened D:\j2sdk14\jre\lib\sunrsasign.jar]
[Opened D:\j2sdk14\jre\lib\jsse.jar]
[Opened D:\j2sdk14\jre\lib\jce.jar]
[Opened D:\j2sdk14\jre\lib\charsets.jar]
[Loaded java.lang.Object from D:\j2sdk14\jre\lib\rt.jar]

And you should know what my classpath is too:

CLASSPATH=d:\java_lib\commapi\samples\BlackBox\BlackBox.jar;.;D:\java_lib\util\systronix_utils.jar;D:\jakarta-ant-1.5.1\lib;;D:\j2sdk14\lib\comm.jar;D:\aJile\Runtime_cldc\Rts;D:\tini1.11\bin;.;D:\java_lib\util\systronix_utils.jar;D:\jakarta-ant-1.5.1\lib;;d:\java_lib\onewire\OneWireAPI_J2ME.jar;D:\Amulet\Projects\applets\Widgets.jar;

and my path:
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Common Files\Adaptec Shared\System;D:\jakarta-ant-1.5.1\bin;D:\j2sdk14\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Common Files\Adaptec Shared\System;

I've got some redundancy to clean up here, but the point is that the JRE is the only portion of the JSDK install which contains runtime libraries such as rt.jar which you can see is where all the PC runtime classes reside. So the JRE folders must always be referenced at runtime. But you don't need to have the javaxcomm classes in the JRE folders, as long as you add the comm.jar to your classpath per the instructions on the PEJ book website. This is also the recommended installation given in the javaxcomm installation instructions.

I'd be curious to see all the Java-related entries in the system registry, and it would be nice to understand how that all relates too.


 
Systronix® 939 Edison St, Salt Lake City, Utah, USA 84111
Tel +1-801-534-1017, Fax +1-801-534-1019
contact us     Time Zone: MDT (UTC-6)
 

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Systronix is independent of Sun Microsystems, Inc.
TStik, JStik, JCX, JStamp, JSimm, JDroid, and JRealTime are trademarks of Systronix, Inc.
1-Wire, iButton and TINI are trademarks of Dallas Semiconductor
Simmstick is a trademark of Dontronics
LEGO® is a trademark of Lego A/S, Denmark