Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Command line environment variable containing spaces

843798Sep 19 2003 — edited Oct 3 2003
Hello,

I need some help passing an environment variable that contains spaces to the JVM when launched via the command line

I can successfully use the following and read its value in the java application:

java -DMYVAR=value.cfg myClass


However, when I try

java -DMYVAR="value1.cfg, value2.cfg, value3.cfg" myClass

I get the following exception
Exception in thread "main" java.lang.NoClassDefFoundError: value2/cfg"

It looks like the inverted commas are being discarded and the JVM is treating value2.cfg as a class to execute

I have run this on
1) a Solaris box with the following details:
SunOS trafford 5.6 Generic_105181-26 sun4u sparc SUNW,Ultra-4
and java version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_04, native threads, sunwjit)

2) an HP box with the following details:
HP-UX wpsc02 B.11.00 U 9000/800 105911507 unlimited-user license
and java version
java version "1.4.1.00"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1.00-030116-09:58)
Java HotSpot(TM) Server VM (build 1.4.1 1.4.1.00-030116-11:27-PA_RISC2.0 PA2.0, mixed mode)


We want to do this so that we can get the value of MYVAR, split up the string using a StringTokenizer on the "," and pick out as many tokens as are present. As a workaround, we can leave out the spaces and it works fine, but it would be useful to be able to allow the spaces

Thanks in advance to anyone who has any ideas about what is happening or how to solve this
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2003
Added on Sep 19 2003
4 comments
568 views