s_lavie
asked on
set JAVA_HOME for a win2000 batch file
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_0 4
or
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_0 4"
doesn't work!
How I can set JAVA_HOME, with a path name that contains spaces?
@set JAVA_HOME=C:\JavaSoft\JRE\
works fine, but
@set JAVA_HOME=C:\Program Files\JavaSoft\JRE\1.3.1_0
or
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_0
doesn't work!
How I can set JAVA_HOME, with a path name that contains spaces?
change Program Files to PROGRA~1
ASKER
What if my directory name is "New Folder"? (and I have also "New Folder1" and "New Folder2")
open a dos window and do dir /X this should give you the short file names.
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%"
JAVA_HOME1=...
JAVA_HOME2=...
And then in your batch file use:
set JAVA_HOME="%JAVA_HOME2%"
ASKER
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...
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...
BTW, exactly how doesn't it work? I don't recall ever having problems with long filenames in batch files.
ASKER
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_0 4
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_0 4"
I get:
JAVA_HOME is not set properly !!!
For:
@set JAVA_HOME="C:\Progra~1\Jav aSoft\JRE\ 1.3.1_04"
I get:
Exception in thread "main" java.lang.NoClassDefFoundE rror: \bin\java
And only:
@set JAVA_HOME=C:\Progra~1\Java Soft\JRE\1 .3.1_04
works fine!
@set JAVA_HOME=
@if EXIST "%JAVA_HOME%\bin\java.exe"
@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_0
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_0
I get:
JAVA_HOME is not set properly !!!
For:
@set JAVA_HOME="C:\Progra~1\Jav
I get:
Exception in thread "main" java.lang.NoClassDefFoundE
And only:
@set JAVA_HOME=C:\Progra~1\Java
works fine!
Try the following:
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_0 4"
@if EXIST %JAVA_HOME%\bin\java.exe GOTO JAVA_HOME_OKAY
@ECHO. JAVA_HOME is not set properly !!!
@GOTO THE_END
:JAVA_HOME_OKAY
@set JAVA_HOME="C:\Program Files\JavaSoft\JRE\1.3.1_0
@if EXIST %JAVA_HOME%\bin\java.exe GOTO JAVA_HOME_OKAY
@ECHO. JAVA_HOME is not set properly !!!
@GOTO THE_END
:JAVA_HOME_OKAY
ASKER
Same as 3:
Exception in thread "main" java.lang.NoClassDefFoundE rror: \bin\java
)-;
Exception in thread "main" java.lang.NoClassDefFoundE
)-;
The problem might be further on in your batch, cause that segment works fine here.
ASKER
Here is the original batch file:
@ECHO OFF
@set JAVA_HOME=C:\JavaSoft\JRE\ 1.3.1_04
@set SERVER_HOME="C:\ProductNam e\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:%SER VER_HOME%\ server.jar -Djava.security.policy=fil e:%SERVER_ HOME%\rmi. policy -jar server.jar
@ECHO ON
@ECHO OFF
@set JAVA_HOME=C:\JavaSoft\JRE\
@set SERVER_HOME="C:\ProductNam
@if EXIST "%JAVA_HOME%\bin\java.exe"
@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
@ECHO ON
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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/se rver/-"
{
permission java.security.AllPermissio n;
};
It runs OK (when folder name has no spaces)!
For:
grant codeBase "file:C:/Test/New Folder/server/-"
{
permission java.security.AllPermissio n;
};
It throws:
RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalExceptio n: error unmarshalling arguments; nested exception is:
java.net.MalformedURLExcep tion: no protocol: Folder\server\server.jar in Server::main()
For:
grant codeBase file:C:/Test/New Folder/server/-
{
permission java.security.AllPermissio n;
};
It throws:
access denied (java.net.SocketPermission 127.0.0.1:1199 connect,resolve) in Server::main()
java.security.AccessContro lException : access denied (java.net.SocketPermission 127.0.0.1:1199 connect,resolve)
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/se
{
permission java.security.AllPermissio
};
It runs OK (when folder name has no spaces)!
For:
grant codeBase "file:C:/Test/New Folder/server/-"
{
permission java.security.AllPermissio
};
It throws:
RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalExceptio
java.net.MalformedURLExcep
For:
grant codeBase file:C:/Test/New Folder/server/-
{
permission java.security.AllPermissio
};
It throws:
access denied (java.net.SocketPermission
java.security.AccessContro
I would have thought the following was correct:
grant codeBase "file:C:/Test/New Folder/server/-"
{
permission java.security.AllPermissio n;
};
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.
grant codeBase "file:C:/Test/New Folder/server/-"
{
permission java.security.AllPermissio
};
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.
ASKER
Is it "possible" that the same (bad) code would work for:
grant codeBase "file:C:/Test/NewFolder/se rver/-"
{
permission java.security.AllPermissio n;
};
???
(Of course its possible, everything is possible with software, but does it make sense?)
grant codeBase "file:C:/Test/NewFolder/se
{
permission java.security.AllPermissio
};
???
(Of course its possible, everything is possible with software, but does it make sense?)
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 :)
ASKER
This line:
Naming.bind("//localhost:1 099/MgmtSe rver");
Causes:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalExceptio n: error unmarshalling arguments; nested exception is:
java.net.MalformedURLExcep tion: no protocol: Folder\server\server.jar
java.rmi.UnmarshalExceptio n: error unmarshalling arguments; nested exception is:
java.net.MalformedURLExcep tion: no protocol: Folder\server\server.jar
java.net.MalformedURLExcep tion: no protocol: Folder\server\server.jar
at sun.rmi.transport.StreamRe moteCall.e xceptionRe ceivedFrom Server(Unk nown Source)
at sun.rmi.transport.StreamRe moteCall.e xecuteCall (Unknown Source)
at sun.rmi.server.UnicastRef. invoke(Unk nown Source)
at sun.rmi.registry.RegistryI mpl_Stub.b ind(Unknow n Source)
at java.rmi.Naming.bind(Unkno wn Source)
at Server.main(Server.java:98 )
... when using "New Folder", but works fine for "NewFolder" - any obvious reason?
Naming.bind("//localhost:1
Causes:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalExceptio
java.net.MalformedURLExcep
java.rmi.UnmarshalExceptio
java.net.MalformedURLExcep
java.net.MalformedURLExcep
at sun.rmi.transport.StreamRe
at sun.rmi.transport.StreamRe
at sun.rmi.server.UnicastRef.
at sun.rmi.registry.RegistryI
at java.rmi.Naming.bind(Unkno
at Server.main(Server.java:98
... when using "New Folder", but works fine for "NewFolder" - any obvious reason?
I think the exception is actually being thrown on the server (when the client tries to connect).
Maybe the codebase used to start your server.
ASKER
The client is not trying to connect.
The exception is being thrown when the server is loaded...
The exception is being thrown when the server is loaded...
ASKER
> 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:%SER VER_HOME%\ server.jar -Djava.security.policy=fil e:%SERVER_ HOME%\rmi. policy -jar server.jar
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
ASKER
Should I use the codebase to start the server?
If I don't it seems to work fine ;-)
If I don't it seems to work fine ;-)
Try:
@set SERVER_HOME=C:\Test\New Folder\server
"%JAVA_HOME%\bin\java" -Djava.rmi.server.codebase ="file:%SE RVER_HOME% \server.ja r" -Djava.security.policy="fi le:%SERVER _HOME%\rmi .policy" -jar server.jar
@set SERVER_HOME=C:\Test\New Folder\server
"%JAVA_HOME%\bin\java" -Djava.rmi.server.codebase
ASKER
Well, I guess I'll skip the codebase when starting my server.
Unless you think it's a bad idea...
Unless you think it's a bad idea...
did the above batch changes help?
ASKER
No )-;
What is the purpose of starting the server with the codebase, anyway? (I just saw that in an example)
What is the purpose of starting the server with the codebase, anyway? (I just saw that in an example)
ASKER
Thanks.