Is ist possible to start a java application with the -X parameters?
I have tried java -jar -Xmx=256m myAppl.jar but with no success.
Is there a possibiliy to do this?
Xmx parameter does not need = symbol, just write Xmx256m
It's more convenient to set it before -jar parameter.
java -Xmx256m -jar myapp.jar
Anyway since you get OutOfMemoryError, I think that = symbol is just a typo (JVM can't start with invalid Xmx parameter) and the real problem is lack of memory. Try to increase it.
Related
Do we need to mandatory specify JVM heap memory arguments in bat file while calling .jar file?
For example:
start /b "" "jre7\bin\javaw.exe" -Xmx1G -jar XYZ.jar
I have the scenario that in some machine when I explicitly specify the arguments(as above) then Java fatal exception is generated!
enter image description here
Error Message:
"Java virtual machine Launcher:
Error: Could not create Java virtual machine.
Error: A fatal exception has occurred. Program will exit."
But when I remove the arguments then no error is reported.
Please anyone let me know. Thank you.
Xmx is an optional argument that specifies the maximum heap size that can be used by Java. It is not required.
If you specify too large a number, you may get a fatal exception. If you don't specify an option, java chooses the max heap size. You can find the default value of this on linux by running 'java -XX:+PrintFlagsFinal -version | grep MaxHeapSize'
You need to update the windows environment variables _JAVA_OPTIONS and set Xmx1024M there. Once done you can start your JVM just fine.
I'm new in the Oracle world and I'm working with Oracle Identity Analytics (OIA). In the test environment everything is ok, but in production environment i'm getting an "java.lang.OutOfMemoryError", so when I checked the Xmx and Xms I saw that I had Xmx:512m and Xms:512m, that's why I'm trying to modify the Xmx value.
I want to modify the Xmx and Xms values so I wrote the following line in my PuTTY:
$ java -Xmx1024m
But the PuTTY shows me the following:
Usage: java [-options] class [args...] (to execute a class) or
java [-options] -jar jarfile [args...] (to execute a jar file)
where options include:...
Seems like I'm forgetting something after "Xmx1024m", but what? Well, now I know I'm forgetting Jar file, Class or App name but I have no idea how to get any of those things. I tried putting "$AdminServer" after "Xmx1024m" but it didn't work.
My Java version is 1.6.0_45 Oracle JRockit build R28 and the Operative Systems is Linux Server 6.5.
Regards!
You have to pass filepath to execute. Of course, you can run
java -Xmx1024m
but Java doesn't know what file should be executed
You will have to pass the program-name/filename/jar-name,whatever it is,with path for which you want to set/reset the java heap size.
e.g
java -Xms1024M -Xmx2048M -jar xi.jar
java -Xmx64m ${PROGRAM_NAME}
Hope this helps you.Or to help you better,could you please tell us what exactly is your scenario?
Is there a way to set -Xmx when i start the application with "./activator start"
I tried (not working):
./activator start -J-Xmx2g
./activator -mem 2048 start
_JAVA_OPTIONS="-Xmx2g" ./activator start
It says
"Picked up _JAVA_OPTIONS: -Xmx2g"
but still not working.
Also tried various values in build.sbt and application.conf - no luck
The only way i could make it work was to use
"stage" and pass -Xmx2g to the generated shell script, which is fine, but it doesn't detach the console.
I think I tried all I found on google but still no luck.
I would like to pass -Xmx to the activator start somehow.
First define an environment variable with your JVM parameters named _JAVA_OPTIONS
export _JAVA_OPTIONS="-Xmx2048m"
and then try the play start or use the activator.
I have found solution. There is some bug in activator shell script, so passing -J-Xmx argument does not remove default mem options. To change mem parameter have a look at your activator script (/usr/local/bin/activator) and have a look how mem parameters are added. Also notice that passing -v argument will print final command to lunch java. Working solution on linux for me is this:
export JAVA_OPTS="-Xmx2700m";activator -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
Examples of not working solution:
_JAVA_OPTIONS="-Xmx2048m";activator -J-Xmx2700m -J-Xms1024m -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-Xmx2700m
-Xms1024m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
Also not working:
activator -J-Xmx2700m -J-Xms1024m -v
# Executing command line:
java
-Dactivator.home=/usr/local/bin
-Xmx2700m
-Xmx2700m
-Xms1024m
-jar
/usr/local/bin/activator-launch-1.3.2.jar
I think you need to specify both, min and max heap size, try this:
activator -J-Xmx2048m -J-Xms2048m start
I'm writing a simple batch script to execute a game quicker (for a dev environment purpose), however I seem to be unable to pass the appropriate command-line arguments to the executable:
#ECHO OFF
set USERNAME=Testing
set MCDIR=%APPDATA%/.minecraft/
set GAMEDIR=%MCDIR%/versions/1.7.5/
set NATIVES=%GAMEDIR%/natives/
java -client -Xmx512M -Xms512M ^
-Djava.library.path=%NATIVES% ^
-cp %GAMEDIR%/1.7.5.jar:^
%MCDIR%/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar:^
%MCDIR%/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar:^
##etc... lots of libs
%MCDIR%/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar:^
%MCDIR%/libraries/org/lwjgl/lwjgl/lwjgl-platform/2.9.1/lwjgl-platform-2.9.1-natives-windows.jar:^
%MCDIR%/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-windows.jar:^
net.minecraft.client.main.Main --username=%USERNAME% --version 1.7.5 --gameDir %MCDIR% --assetsDir %MCDIR%/assets --userProperties {} --accessToken Offline
pause
However this small script seems to fail the instant it goes beyond client.main.Main with any argument, effectively treating it as a JVM argument rather than a command-line program argument. Is there a different way to go about doing this when using -cp rather than -jar for calling a program in java? If not, what am I doing wrong?
It appears that there is no space between the end of your path (the last ^) and your Main class, so your Main class is effectively part of the -cp JVM argument. There is no class yet, so java still sees JVM args.
Try putting a space after the last part of the -cp value and your net.minecraft.client.main.Main, to separate the -cp value and your class on the command line.
I've searched throughout this site and tried a few solutions when receiving this message but nothing seems to work.
I am trying to invoke a shell script on Ubuntu 12.04.2 (with java-7-openjdk-amd64) that runs a java program and then I get a "Error: Could not find or load main class com.xx" error.
This is how my script invokes Java:
"$JAVA" $server_jvmargs $javaProps -Dxx.home="$XX_HOME" -Duser.dir="$XX_HOME" -cp $client_classpath $mainclass $args
And the arguments you see above are defined as follows:
args=$*
javaProps=
mainclass=com.xx
server_jvmargs="-Djava.awt.headless=true -Xms1024m -Xmx1024m $jvmargs"
XX_HOME="`pwd`/../.."
client_classpath="$XX_HOME/lib/client/patch.jar;$XX_HOME/lib/client/xyx-xxx.jar;$clientlibs;$XX_HOME/lib/server/standard-1.1.2.jar;$publictilesource;$respath;$XX_HOME/lib/client/xxmainclass.jar"
The mainclass variable is in the classpath located in the xxmainclass.jar file so I'm not sure as to why it cannot find it?
Does anyone have any ideas on what could be going on?
To see what actually happens when you run your script, invoke it with bash -x, or put set -x at the top; this will print each command before it's run, so you can see how it's actually starting the JVM. Without this information, it's hard to come up with a better diagnosis. That said...
You've been copying off Tomcat's startup scripts, it looks like. Don't; they're awful.
Something a little more correct on the shell side might look like this:
args=( "$#" )
javaProps=( )
mainclass=com.xx
server_jvmargs=( -Djava.awt.headless=true -Xms1024m -Xmx1024m "${jvmargs[#]}" )
XX_HOME="$PWD/../.."
client_classpath="$XX_HOME/lib/client/patch.jar:$XX_HOME/lib/client/xyx-xxx.jar:$clientlibs:$XX_HOME/lib/server/standard-1.1.2.jar:$publictilesource:$respath:$XX_HOME/lib/client/xxmainclass.jar"
java \
"${server_jvmargs[#]}" \
"${javaProps[#]}" \
-Dxx.home="$XX_HOME" \
-Duser.dir="$XX_HOME" \
-cp "$client_classpath" \
"$mainclass" "${args[#]}"
The use of ${foo[#]} expands the array foo with literal contents. Note that foo must be created as an array in this case, and you need to be using a shell that supports arrays (so your script needs to start with #!/bin/bash, not #!/bin/sh).
See http://mywiki.wooledge.org/BashFAQ/005 for an introduction to arrays in bash.
use a : instead of a ; in your classpath.
unix just rolls that way.
Try this:
Java -jar pathToYOurFile.jar
Please check if line end character is OS specific in your shell script