Solved

set JAVA_HOME for a win2000 batch file

Posted on 2002-07-28
29
582 Views
Last Modified: 2008-02-01
I wrote a .bat file to run a java application on win2000:
@set JAVA_HOME=C:\JavaSoft\JRE\1.3.1_04
works fine, but
@set JAVA_HOME=C:\Program Files\JavaSoft\JRE\1.3.1_04
or
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_04"
doesn't work!

How I can set JAVA_HOME, with a path name that contains spaces?
0
Comment
Question by:s_lavie
  • 14
  • 13
  • 2
29 Comments
 
LVL 1

Expert Comment

by:klf
ID: 7183543
change Program Files to PROGRA~1
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7183551
What if my directory name is "New Folder"? (and I have also "New Folder1" and "New Folder2")
0
 
LVL 1

Expert Comment

by:klf
ID: 7183745
open a dos window and do dir /X this should give you the short file names.
0
 
LVL 92

Expert Comment

by:objects
ID: 7184216
Try setting the various different homes in your system environment:

JAVA_HOME1=...
JAVA_HOME2=...

And then in your batch file use:

set JAVA_HOME="%JAVA_HOME2%"
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184495
klf,
I want to set this variable automatically during installation (using the JavaHome registry value).
Is there a way to find the short file name in runtime (using java or whatever).
My installation application is generated by InstallShield Multi Platform.

objects,
I wish not to set a system environment unless it's a must...
0
 
LVL 92

Expert Comment

by:objects
ID: 7184513
BTW, exactly how doesn't it work?  I don't recall ever having problems with long filenames in batch files.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184542
The relevant part in my batch is as following:

@set JAVA_HOME=
@if EXIST "%JAVA_HOME%\bin\java.exe" GOTO JAVA_HOME_OKAY
   @ECHO.   JAVA_HOME is not set properly !!!
   @GOTO THE_END
:JAVA_HOME_OKAY

Now,
For:
@set JAVA_HOME=C:\Program Files\JavaSoft\JRE\1.3.1_04
I get:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.

For:
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_04"
I get:
JAVA_HOME is not set properly !!!

For:
@set JAVA_HOME="C:\Progra~1\JavaSoft\JRE\1.3.1_04"
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: \bin\java

And only:
@set JAVA_HOME=C:\Progra~1\JavaSoft\JRE\1.3.1_04
works fine!
0
 
LVL 92

Expert Comment

by:objects
ID: 7184568
Try the following:

@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_04"
@if EXIST %JAVA_HOME%\bin\java.exe GOTO JAVA_HOME_OKAY
  @ECHO.   JAVA_HOME is not set properly !!!
  @GOTO THE_END
:JAVA_HOME_OKAY

0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184591
Same as 3:
Exception in thread "main" java.lang.NoClassDefFoundError: \bin\java
)-;
0
 
LVL 92

Expert Comment

by:objects
ID: 7184614
The problem might be further on in your batch, cause that segment works fine here.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184625
Here is the original batch file:

@ECHO OFF

@set JAVA_HOME=C:\JavaSoft\JRE\1.3.1_04
@set SERVER_HOME="C:\ProductName\server"

@if EXIST "%JAVA_HOME%\bin\java.exe" GOTO JAVA_HOME_OKAY
   @ECHO.
   @ECHO.  
   @ECHO.   JAVA_HOME is not set properly !!!
   @ECHO.
   @ECHO.   (Please set the JAVA_HOME environment variable)
   @ECHO.
   @ECHO.  
   @PAUSE
   @GOTO THE_END
:JAVA_HOME_OKAY

%JAVA_HOME%\bin\java -Djava.rmi.server.codebase=file:%SERVER_HOME%\server.jar -Djava.security.policy=file:%SERVER_HOME%\rmi.policy -jar server.jar

@ECHO ON
0
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 7184661
Try:

@ECHO OFF

@set JAVA_HOME=C:\Program Files\JavaSoft\JRE\1.3.1_04
@set SERVER_HOME="C:\ProductName\server"

@if EXIST "%JAVA_HOME%\bin\java.exe" GOTO JAVA_HOME_OKAY
  @ECHO.
  @ECHO.  
  @ECHO.   JAVA_HOME is not set properly !!!
  @ECHO.
  @ECHO.   (Please set the JAVA_HOME environment variable)
  @ECHO.
  @ECHO.  
  @PAUSE
  @GOTO THE_END
:JAVA_HOME_OKAY

"%JAVA_HOME%\bin\java" -Djava.rmi.server.codebase=file:%SERVER_HOME%\server.jar -Djava.security.policy=file:%SERVER_HOME%\rmi.policy -jar server.jar

@ECHO ON
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184725
Great!
While in this subject, I wonder whether you have something for this (extra points is a promise):

In my policy file:

grant
{
 // Allow everything for now
 permission java.net.SocketPermission  "*:1024-65535", "accept, connect, listen";
};

grant codeBase "file:C:/Test/NewFolder/server/-"
{
 permission java.security.AllPermission;
};
It runs OK (when folder name has no spaces)!

For:
grant codeBase "file:C:/Test/New Folder/server/-"
{
 permission java.security.AllPermission;
};
It throws:
RemoteException occurred in server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.net.MalformedURLException: no protocol: Folder\server\server.jar in Server::main()

For:
grant codeBase file:C:/Test/New Folder/server/-
{
 permission java.security.AllPermission;
};
It throws:
access denied (java.net.SocketPermission 127.0.0.1:1199 connect,resolve) in Server::main()
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1199 connect,resolve)
0
 
LVL 92

Expert Comment

by:objects
ID: 7184746
I would have thought the following was correct:

grant codeBase "file:C:/Test/New Folder/server/-"
{
permission java.security.AllPermission;
};

The exception you are getting may not be related to the policy entry. And you are just experiencing it because the (bad) code is getting permission to execute.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:s_lavie
ID: 7184757
Is it "possible" that the same (bad) code would work for:
grant codeBase "file:C:/Test/NewFolder/server/-"
{
permission java.security.AllPermission;
};
???
(Of course its possible, everything is possible with software, but does it make sense?)
0
 
LVL 92

Expert Comment

by:objects
ID: 7184773
Maybe as the url that it is blowing up on will be different. Find where that URL is specified and u may find your problem :)
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184805
This line:
Naming.bind("//localhost:1099/MgmtServer");
Causes:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.net.MalformedURLException: no protocol: Folder\server\server.jar
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:

        java.net.MalformedURLException: no protocol: Folder\server\server.jar
java.net.MalformedURLException: no protocol: Folder\server\server.jar
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
        at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
        at java.rmi.Naming.bind(Unknown Source)
        at Server.main(Server.java:98)

... when using "New Folder", but works fine for "NewFolder" - any obvious reason?
0
 
LVL 92

Expert Comment

by:objects
ID: 7184832
I think the exception is actually being thrown on the server (when the client tries to connect).
0
 
LVL 92

Expert Comment

by:objects
ID: 7184835
Maybe the codebase used to start your server.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184837
The client is not trying to connect.
The exception is being thrown when the server is loaded...
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7184859
> Maybe the codebase used to start your server.
I guess it is (I use the above batch file):

@set SERVER_HOME="C:\Test\New Folder\server"

"%JAVA_HOME%\bin\java" -Djava.rmi.server.codebase=file:%SERVER_HOME%\server.jar -Djava.security.policy=file:%SERVER_HOME%\rmi.policy -jar server.jar
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7185027
Should I use the codebase to start the server?
If I don't it seems to work fine ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 7186844
Try:

@set SERVER_HOME=C:\Test\New Folder\server

"%JAVA_HOME%\bin\java" -Djava.rmi.server.codebase="file:%SERVER_HOME%\server.jar" -Djava.security.policy="file:%SERVER_HOME%\rmi.policy" -jar server.jar
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7187827
Well, I guess I'll skip the codebase when starting my server.
Unless you think it's a bad idea...
0
 
LVL 92

Expert Comment

by:objects
ID: 7189289
did the above batch changes help?
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7189763
No )-;
What is the purpose of starting the server with the codebase, anyway? (I just saw that in an example)
0
 
LVL 92

Expert Comment

by:objects
ID: 7192145
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7192567
Thanks.
0
 
LVL 92

Expert Comment

by:objects
ID: 7192631
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 76
GUI builder for Eclipse? 8 27
fibonacci ten numbers 4 24
table example 4 20
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now