how to change the amount of java memory heap for Jason-JEdit generated processes?
I'm running code edited in Jason-JEdit, as part of the application a NetLogo process is started, originated by the first one, but a heap size error appears.
The main process in Jason-Jedit is:
user 6006 6003 9 19:44 ? 00:00:02 java -Xms256m -Xmx1024m -classpath ~/Jacamo/lib/jacamo.jar:/usr/local/lib/netlogo5.2/NetLogo.jar:. -jar ~/Jason-1.4.2/bin/jedit/jedit.jar
The generated process from Jason-Jedit are:
1-The normal launcher process of the agent
user 6055 6006 11 19:44 ? 00:00:00 /usr/lib/jvm/java-7-oracle/bin/java -classpath ~/Jacamo/lib/ant-launcher.jar org.apache.tools.ant.launch.Launcher -e -f bin/build.xml run
2- The NetLogo lauched process
user 6069 6055 99 19:44 ? 00:00:05 /usr/lib/jvm/java-7-oracle/jre/bin/java -classpath ~/JaCaMo/workingDir:~/JaCaMo/workingDir/bin/classes:~/Jacamo/lib/jason.jar:/usr/local/lib/netlogo5.2/NetLogo.jar jason.infra.centralised.RunCentralisedMAS systemMAS-JNL.mas2j
As it can be seen the generated processes do not have the heap size option: -Xms256m -Xmx1024m, as the first one process does.
I already tried the following:
1) Edit the jason.sh/Jacamo.sh files adding:
java -Xms256m -Xmx1024m -classpath [...]
2) Add the variable _JAVA_OPTIONS in the .profile
export _JAVA_OPTIONS="-Xms256m -Xmx1024m"
And this works for the main process only, the Jason-Jedit application, but the problem persist in the generated process. Any idea about how to change the settings in JEdit?
I don't think this has anything to do with jEdit itself, as it is just shipped and used as editor and host for the custom plugin the jason project is providing. From a very short look at the plugin code, I'd say it generates an Ant build script that starts the RunCentralisedMAS class and it doesn't inject any jvmargs into this Ant build script. But the build-template.xml file has a commented-out line with jvmargs. So I guess if you search for the build-template.xml file and change it so that the jvmarg are set, it will work for you.
I have installed multiple versions of JDK, including 1.6,1.7,1.8.
I want to know which version of java.exe gets executed when I run software that needs JRE. I did some testing, see below:
Tests:
cmd.exe command: echo %java_home%
prints: java version "1.8.0_31"
cmd.exe command: java -version
prints: java version "1.8.0_31"
Then I checked the register table in HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8 and got the javaHome key value
result: C:\Program Files\Java\jdk1.8.0_31.
java code: System.out.println(System.getProperty("java.home"));
prints: C:\Program Files (x86)\Java\jdk1.7.0_15\jre
Finally, I opened the task manager, searched the java.exe process and located the java.exe directory at:
result: C:\Program Files (x86)\Java\jdk1.7.0_15\bin
Question:
I'm confused which jave.exe file the computer chooses. Can you help?
Passive approach
You may want what the where windows command line utility does; assuming you have only one java.exe in your %PATH%
Try:
where java.exe
If you have multiple version of java pin your %PATH% this will return multiple values. (unfortunately)
Active approach
Set your environment this way:
Have your PATH environment variable to point ONLY to c:\tools\java\default
Store all your jre in one folder like
C:\tools\Java\JRE_1.6
C:\tools\Java\JRE_1.7
C:\tools\Java\JRE_1.8
Then open a comman propt and inside C:\tools\Java\ execute
junction default JRE_1.6
This will create a junction (wich is more or less like a symbolic lync).
In this way you will always have your default java in c:\tools\java\default.
If you then need to change your default java to the 1.8 version you just neet to execute
junction -d default
junction default JRE_1.8
From information you provided your default java is set to java 8 and the program you run is like to be run in some ide that use java 7.
Java -version command gives the default set java in your system.
I am able to run a Java program through Eclipse by setting the VM arguments as -Xmx1024m
-Xms256M. Now I want to run the same Java program (jar) through a .bat file in Windows. I am setting the JVM values in the file as follows
#echo off
set JAVA_OPTS="-Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError"
java -cp TA.jar com.myClass
But when I run the same program through batch (.bat in Windows XP) it throws Out of Memory error and I suspect that the JVM setting through the .bat file is not working.
It should be _JAVA_OPTIONS instead of JAVA_OPTS.
Use the arguments directly
java -Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError -cp TA.jar com.myClass
You don't need to set them at JAVA_OPTIONS. To be sure that your application is using the parameters that you want:
open jvisualvm that comes with java. Just type "jvisualvm" at command line if you have set java correctly at your path.
open the vm started to your application.
check under "JVM Arguments" in the "Overview" tab.
There should be set your jvm options.
Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.
In macOS X 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique.
Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home in your path add it like this.
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
References:
Oracle explains the java_home command
An article for configuring the JDK in Spring Tool Suite (Eclipse
2019) on MacOS
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in
$ echo $JAVA_HOME
it shows
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test
$ which java
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.
That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.)
Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here:
Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #hygull method
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
This method tested working in macOS Mojave Version 10.14.6.
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my .bash_profile:
export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
As other answers note, the correct way to find the Java home directory is to use /usr/libexec/java_home.
The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
For me maven seems to work off the .mavenrc file:
echo "export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" > ~/.mavenrc
I'm sure I picked it up on SO too, just can't remember where.
Create file ~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v 1.8)
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
For Fish Shell users, use something like the following: alias java7 "set -gx JAVA_HOME (/usr/libexec/java_home -v1.7)"
Is there a way that I can set the default heap size for the jvm on my own computer? I want to set it to 1g, because I'm always running custom programs that always hit the overage point in the default jvm size.
I just dont want to have to remember to type -XmX1g everytime I run my java app from the command line...
There has to be an admin way to do this right?
Apparently, _JAVA_OPTIONS works on Linux, too:
$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
For Windows users, you can add a system environment variable named _JAVA_OPTIONS, and set the heap size values there. The JVM should be able to grab the virtual machine options from _JAVA_OPTIONS.
This worked for me:
export _JAVA_OPTIONS="-Xmx1g"
It's important that you have no spaces because for me it did not work. I would suggest just copying and pasting. Then I ran:
java -XshowSettings:vm
and it will tell you:
Picked up _JAVA_OPTIONS: -Xmx1g
what platform are you running?..
if its unix, maybe adding
alias java='java -Xmx1g'
to .bashrc (or similar) work
edit: Changing XmX to Xmx
if the platform is Linux, then adding an entry in bash_profile will help.
vim ~/.bash_profile
then add
export _JAVA_OPTIONS="-Xmx4g"