I'm writting a Java Launcher Program, that should display installed Java programs and launch them, if needed.
Therefore i use the Runtime.getRuntime().exec() method with java.exe -jar myjar.jar as argument.
This works so far, but i also need to pass custom proxy settings to the jvm. From the command line this is possible with:
java.exe -http.proxyHost=www.example.com -http.proxyPort=80 -jar myjar.jar
But if i run this command in java it states:
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -http.proxyHost=www.example.com
So the question: Am i doing something wrong or is this not possible?
Thanks in Advance.
Runtime options should have a D at the beginning:
java.exe -Dhttp.proxyHost=www.example.com -Dhttp.proxyPort=80 -jar myjar.jar
Related
I'm launching javaw -viewer command through command prompt, I'm getting pop-up error message saying that,
Error : Coud not create Java Virtual Machine.
Error : A fatal exception has occured. Program will exit.
but the remaining command are working fine.
like java -version
See the image for error:
One more point I want to add, I'm running jdk1.7 also in my machine.
There's no such command as javaw -viewer. Perhaps you meant javaws -viewer?
It is possible run a jar that I have inside another jar from my class?
I´m trying to run this command from my class
java -cp //file:/D:/Users/nb38tv/workspace/f2e-core/f2e-mock/f2e-test-framework/target/f2e-test-framework-1.8.3-SNAPSHOT.jar!/h2/sakila-h2-master/h2-1.3.161.jar -ifExists -tcp -web -tcpAllowOthers
But java complain since cannot find the jar.
If I remove the ! from the path I receive this error
Unrecognized option: -ifExists
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
It is not possible to execute a jar embedded in a jar like that, but even if it were possible, your Java command line is simply incorrect. That is because the -ifExists (and the other options) are interpreted as commandline options of the java executable.
You will get the same error message if you extract that h2-1.3.161.jar from the f2e-test-framework-1.8.3-SNAPSHOT.jar and tried to execute it with the same command line.
It would either need to use -jar instead of -cp, or you would need to specify the class to run before -ifExists.
I obtain different results using the same program when I run it thru:
1)..\Desktop\app.jar
2)..\Desktop\java -jar app.jar
second case gives the same result that I saw in eclipse but it uses console.
Question is: How do I force my program to work properly (to give the same result as in eclipse) by direct executing app.jar (without console)?
Use javaw instead of java in command line:
..\Desktop\javaw -jar app.jar
More information: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html
I know that the java -jar filename.jar is used for executing the jar file using command prompt, but could anyone please explain the following command:
java -jar filename.jar -debug
What is the exact use of the -debug in the above command?
This is not a flag for the Java Interpreter (as those should be passed before the actual class/jar).
If you execute the command-line you posted above, this will launch your filename.jar-files main class and give it's main(String[] args)-method the -debug-parameter as the second argument in the args-array.
But, there is (or was) also the -debug flag from older Java versions, which has been replaced by the -Xdebug flag. The (certainly old) manpage states that:
-debug Allows the Java debugger - jdb(1) - to attach
itself to this java session. When -debug is
specified on the command line java displays a
password that must be used when starting the
debugging session.
If a Java application is launched with the debug flag, remote-debuggers can attach to the running application and you can (for example) monitor it using JConsole
I'm trying to wrap a program of mine to work with java.
I tried a simple "hello world" first,
-hello world.m-
disp('hello world');
I used deploytool and selected java package.
when it reached this line:
Executing command: "javac -verbose -classpath "C:\Program Files\MATLAB\R2009b\toolbox\javabuilder\jar\javabuilder.jar" -d "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\classes" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\helloworld.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\DeployTutorial2MCRFactory.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\helloworldRemote.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\package-info.java""
I got this error:
'javac' is not recognized as an internal or external command,
operable program or batch file.
Error: An error occurred while shelling out to javac (error code = 1).
Unable to build executable.
btw: when I tried standalone application / c/c++ shared library it has been compiled successfully.
thanks in advance
Possibly the Java SDK is not installed or properly configured on your machine. Open a system terminal and execute the following two commands:
java -version
javac -version
If they both work you should proceed with the examples from the MATLAB help. If not install the Java SDK.
First you should install JAVA.
Then you must set the environment variable in "my computer"
Add a new variable named "JAVA_HOME" and set its value to your jdk path
like D:\Program\Java\jdk1.6.0_25
Then restart your matlab
and type
getenv JAVA_HOME
you should get
ans=
D:\Program\Java\jdk1.6.0_25