How To add some arguments into JVM? [duplicate] - java

I want to specify some JVM arguments when calling a jar file like so:
java -jar filename.jar
I assumed I did it like so:
java -Xms256m -Xmx512m -Djava.awt.headless=true jar filename.jar
But this doesn't seem to work. What am I doing wrong?

Do it like:
java -Xms256m -Xmx512m -Djava.awt.headless=true -jar filename.jar

java [Options] -jar [jarfile] [Command Line Arguments]
Please refer
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

Don't put a space between the -D and java.awt.headless=true.
It should be -Djava.awt.headless=true.

hype jar was missing , try
java -Xms256m -Xmx512m -Djava.awt.headless=true -jar

Related

How to put '-XX:+UseG1GC -Xmx1g -Xms512m' parameters for a .jar in the service wrapper?

I have a jar named my-app-0.0.1-SNAPSHOT.jar. I have to pass -XX:+UseG1GC -Xmx1g -Xms512m to the jar like
sudo java -XX:+UseG1GC -Xmx1g -Xms512m -jar my-app-0.0.1-SNAPSHOT.jar
I've created the .sh using above command. I use this single line bash script file in my-app.service to execute the .jar. Now I need to put everything in .service file. No .sh in picture. How to put those in the .service file? Any help is appreciated.

Set heap size for -jar command

I want to set heap size under Linux OS in order to use it on java -jar command.
I have tried to add _JAVA_OPTIONS property under .bash_profile, but this property is ignored. I know I can run my jar with
java $_JAVA_OPTIONS -jar
command or create an alias like
alias java='java -Xms256m -Xmx512m'
I have found I can also export _JAVA_OPTIONS:
export _JAVA_OPTIONS="-Xms256m -Xmx512m"
But this property is not kept between sessions.
Any idea how can I set permanent heap size for java -jar command?

Running jar via code- Java

final String dir = "C:\\Users\\theo\\Desktop\\1.6 test\\craftbukkit.jar";
Process proc = Runtime.getRuntime()
.exec("java -Xmx1024M -jar "+ dir +" -o true PAUSE");
So.I did some research around here but this thing apparently is not working/running the JAR file.
Note the space in the path of the jar. This means, in the command you build up it will be seen as two arguments:
java -Xmx1024M -jar C:\Users\theo\Desktop\1.6 test\craftbukkit.jar -o true PAUSE
Try to quote the path to build a command like this:
java -Xmx1024M -jar "C:\Users\theo\Desktop\1.6 test\craftbukkit.jar" -o true PAUSE
You need to provide the full path to the Java executable, not just 'java'.
Assuming the program in question is well-behaved, you could use reflection to invoke the main method on the jar's main class without starting up a new JVM.

How increase memory of org.eclipse.ant.core.antRunner

I am running the Eclipse ant runner from command line in the following way:
set LAUNCHER=%ECLIPSE_SDK%\eclipse\plugins\org.eclipse.equinox.launcher_1.1.3.0.jar
%JAVA_HOME%\bin\java.exe -jar %LAUNCHER% -application org.eclipse.ant.core.antRunner -propertyfile %PROPERTIES% -buildfile build.xml
How do I increase the memory provided to this jvm instance ? I am asking this because I am facing OutOfMemory errors in the heap space and adding -vmargs -Xmx512m to the command line didn't fixed the issue
In order to see if -vmargs are taken into account I simply wrote the folowing task:
public class DisplayTask extends Task {
#Override
public void execute() throws BuildException {
System.out.println(Runtime.getRuntime().maxMemory() / 1000000);
}
}
and just launch it in my build.xml (using taskedf to define the task). The output is always 66 whatever I put in -vmargs -Xmx ....
I got it, the solution is to add -Xmx512m option just after the java.exe as folowing:
%JAVA_HOME%\bin\java.exe **-Xmx512m** -jar %LAUNCHER% -application org.eclipse.ant.core.antRunner -propertyfile %PROPERTIES% -buildfile build.xml
This is finally NORMAL. Only the eclipse.exe executable understands the -vmargs flag; when I run java -jar LAUNCHER then I am creating the VM and must thus specify the arguments myself.
you could try setting the ANT_OPTS system variable: http://www.liferay.com/community/wiki/-/wiki/Main/Ant+opts
If you're using native Equinox Launcher (which you're not but probably should - Eclipse ships with carefully crafted VM args) you should know about --launcher.appendVmargs parameter (see The Eclipse runtime options, Eclipse/149994 and eclipse.ini for details
# eclipse --launcher.appendVmargs -vmargs -Xmx512m -application org.eclipse.ant.core.antRunner -propertyfile %PROPERTIES% -buildfile build.xml

Error executing: java -Xms512M -Xmx1024M

$ java -Xms512M -Xmx1024M
While running the above command I got the error below. Please help me how to set JVM Heap memory in AIX box. Here I'm using java 5.
Usage: java [-options] class [args...]
(to execute a class) or java -jar [-options] jarfile [args...]
(to execute a jar file)
where options include:
-cp -classpath <directories and zip/jar files separated by :>
set search path for application classes and resources
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version
-showversion print product version and continue
-? -help print this help message
-X print help on non-standard options
Well, you have to execute SOME java program, not just the JVM. The options itself are fine. Try java -Xms512M -Xmx1024M -cp somejar.jar mystuff.Main or something.
What about export JAVA_OPTS="-Xms512M -Xmx1024M" (unix) or set JAVA_OPTS=-Xms512M -Xmx1024M (windows)?
Try This also :
java -Xms512M -Xmx1024M -classpath jar1.jar:jar2.jar packageName.YourMainClassName Arguments

Categories

Resources