I'm trying to export my application to a JAR file. The program uses a lot of memory, so I used -Xmx1500m in Eclipse to make it work. It works when I export it (no errors), but it says VM arguments will not be part of the runnable JAR. How can I add the -Xmx1500m to my application outside of Eclipse? I tried a batch file with java -Xmx1500m but it didn't work. Any suggestions?
Try to use something like this:
java -jar yourJarName.jar arg1 arg2
Related
I have 3 files :
MyApp.jar
start.cmd
start.sh
Here is what's in the start files :
java -cp MyApp.jar -Xms256m -Xmx1024m com.companyname.launch.Launcher someArgs -DsomeParameter=true
As you can guess, I have to start the application by executing the correct start file, depending on the OS I'm using.
Is there a simple solution to get rid of the start files, and have only a system independent executable jar file ?
You can run this from Java.
Have a FirstMain which doesn't depend on anything. e.g. can be run without command line arguments. This main start another java program for the same JAR starting the RealMain with all the command line arguments you need.
I am under the impression that Launch4J cannot create launchers for OS X. Correct me, if I am wrong.
I would like to use something similar so I can set the initial heap size/ max heap size for my Java application without using command line options (java -jar -Xmx1024m etc....).
Any recommendations?
What you want is an Application Bundle. It include a properties file (Info.plist) where you can set things like Xmx, etc.
You can also use Oracle's appbundler tool to create an application bundle.
Another no-brainer option is to create a shell script. Something like this:
#!/bin/bash
java -jar myJar.jar
Eclipse can export a run configuration as a runnable jar file or a Mac OSX application bundle.
In the run configuration, add the command line options to the VM arguments textbox in the arguments tab.
I've been reading up on this error but am now confused. I'm trying to run my java test file from the win7 cmd line but am getting that dreaded error cannot find class in classpath.
The script runs fine as a testNG file inside the Eclipse IDE but not from the cmd line.
My classpath dump:
C:\lib\selenium-java-2.37.0.jar;
C:\lib\selenium-server-standalone-2.37.0.jar;
C:\EclipseIDE\ProteinBar\bin;
C:\EclipseIDE\ProteinBar\src\com\proteinbar\staging;
C:\TestNG;
My cmd line test string:
java -cp C:\lib\*;C:\EclipseIDE\ProteinBar\bin org.testng.TestNG DeleteBillingAddress.xml
Thanks for any help...
it doesn't appear that the testng jars are on your classpath. I'm guessing they live under c:/testng so you'll want to add something to your -cp reflecting that.
You need to specify the jars individually, e.g.,
java -cp C:\lib\selenium-java-2.37.0.jar;C:\lib\selenium-server-standalone-2.37.0.jar;...
I have to get some kinks out of a shell script for work, and one of the line looks like this:
-cp: this is the classpath
This is the set of classes that are used when running a specific class.
In your example; OrganT.Tune.Mix OrganT must be a class in the classpath (in this case, inside the OrganT.jar
Read the documentation, can be found here
Just a hint - under linux and mac you can use the
man <command goes here>
comman in the terminal/shell to display all parameters and usage information available for the specific command.
-cp stands for classpath. The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes.
java -classpath .;YourJarFile.jar
I think you want to run a script for including the class path and execute the jar.
To do this in any text editor type java -jar YourJarFile.jar and save it, with extention (anyName.sh) assuming you have got linux flavour. Make it executable using the command chmod 775 anyName.sh
For windows type java -jar YourJarFile.jar, and save it with extention (anyName.bat)
I've been using Powershell-1.0 for command line needs for a while, instead of cmd.exe. Unfortunately, there are still some caveats when using Java. I need to pass a property to a jar, like that:
java -jar -Duser.language=en any.jar
This line works fine in cmd.exe, but not in Powershell as it searches for another jar:
Unable to access jarfile user.language=en
Using quotes doesn't help.
Is it doable in Powershell-1.0, or do I miss something in Java?
Take a look at my answer to this question. Note how you can use echoargs.exe to diagnose these sort of problems. Most likely the fix would be to quote the parameter e.g.:
java -jar "-Duser.language=en" any.jar
You can test that using echoargs (from PowerShell Community Extensions):
echoargs -jar "-Duser.language=en" any.jar
Arg 0 is <-jar>
Arg 1 is <-Duser.language=en>
Arg 2 is <any.jar>
Using quotes works fine for me in PowerShell on Windows 7.
java "-Dmy.property=value" -jar myjar.jar
Be careful: the jar name must be placed right after -jar, and arguments placed after -jar myjar.jar will be passed to the program inside the jarFile.
Try launching instead using the following pattern:
java -Duser.language=en -jar any.jar
That assumes that user.language is meant as a system property. If you meant it as a command line argument, change that to:
java -jar any.jar -Duser.language=en
I am actually surprised that the command line you mentioned works at all outside of powershell (though I have confirmed that it works fine for me too, even on Linux) and it is also a little strange that things would work differently inside and outside of powershell.
From java -help:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
...
-D<name>=<value>
set a system property
...
So basically you should always put the JAR filename directly after the -jar command line option, and any JVM options (such as setting system properties with -D) before.