Set the default GC of JDK, without VM argument - java

For now, when I want to run a jar, I am running it like this: java -XX:+UseZGC -jar app.jar.
The JDK which I am using is eclipse temurin 17 which is using G1GC by default.
But I want to change it with ZGC.
It is possible to change the default GC of jdk? Or to specify in pom.xml to use ZGC?

Related

Confused about what jdk and jre my command prompt is using for java

I was super confused about compatibility on a java tool I was using and ended up downloading different versions of java so now I do not know what versions of jdk or jre I am actually using. When I compile I use -- release 8 in my command prompt, what does that exactly mean?
Currently my programs folder has jdk-18 in the java folder
and my program files(x86) folder has
jdk1.6.0_45
jdk 1.7.0_80
jre 1.8.0_ 321
jre6
jre7
My java home environment variable is C:\Program Files\Java\jdk-18
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
when I type java -version in my command prompt I get
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) Client VM (build 25.321-b07, mixed mode)
So does that mean my cmd uses jre 1.8.0_ 321? What about the jdk? How do I change it if I need to?
When you run java -version - first java found in PATH environment variable is used. To be sure use commands where java (Windows) or which java (Linux) - it will tell you the location.
When you run mvn install - JDK found in JAVA_HOME environment variable is used. To be sure use mvn -version - it will tell you the location.
When you run from IDE - IDE settings matter, usually you specify JDK per project.
When you run javac --release 8 Something.java you are asking compiler to produce output compatible with the version you specified - it has nothing to do with JDK you are actually running it on. This flag was added in JDK 9, so if it doesn't fail for you then it means you are running on JDK>=9.
If you want to be 100% sure just fully qualify the path - for example on Windows "C:\Program Files\Java\jdk1.8.0_152\bin\javac.exe" Something.java
So does that mean my cmd uses jre 1.8.0_ 321?
Yes.
What about the jdk?
Unclear.
Run javac -version and that will tell you what version compiler you will run by default.
The versions of the Java tools that you get when you type java, javac, jar (etcetera) at the CMD prompt are solely determined by the PATH environment variable setting in effect at the command prompt.
The other variables do other things ... but not this.
How do I change it if I need to?
If you want to change what typing java does, change PATH.
Note that the PATH variable is a standard Windows environment variable that affects all* commands, not just the Java tools. There should be lots of tutorials on how to set PATH, and on the Windows CMD prompt in general. You should probably take the time to read them.
You can also just use the absolute path for the Java tools; e.g. "C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe" is probably the correct path for the Java 7 java command. (You can easily check ... and find the correct path by looking at the installation tree.)
Regarding your other variables:
My java home environment variable is C:\Program Files\Java\jdk-18
That is presumably JAVA_HOME. That tells (many) 3rd-party tools which Java tools to use. But unless you have configured PATH to depend on JAVA_HOME, it won't alter what typing java does.
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
That is presumably CLASSPATH. That variable provides a default path that java will use to find classes to load. For example, if you run java com.acme.Example, it will use CLASSPATH to search for the compiled Example class.
So "C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar" is almost certainly incorrect. (That JAR file contains the classes that implement various Java tools. It doesn't need to be on the classpath, unless your Java application is running one of those tools. And even then there would need to be other things on the classpath for your application to work.
You need to do some reading on what the Classpath is, how it works, and how to set it correctly. Setting it to stuff randomly is a sure fire way to make your Java code not work ...

Set the jruby jvm without changing the JAVA_HOME

Is it possible to change the jre used by jruby without changing the JAVA_HOME environment variable in Windows?
I am running jruby with the jruby.exe but couldn't find any parameter for the jre path. I don't want to change my JAVA_HOME (which is Java 1.6) because it will affect other applications on my machine, but I just want to specify to Jruby to use the Java 1.7 jre otherwise I am getting errors.
I am using jruby 1.7.23.
if you set JAVA_HOME in the cmd line or "hard-code" it in a jruby.bat launcher (discouraged but if you must ...) that would only change it for the process run from that particular cmd line.

Where does Maven set Java options? [duplicate]

When building a Java 8 project with Maven:
mvn clean package
I get this message:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
How to remove this message?
Compatibility Guide for JDK 8 says that in Java 8 the command line flag MaxPermSize has been removed. The reason is that the permanent generation was removed from the hotspot heap and was moved to native memory.
So in order to remove this message
edit MAVEN_OPTS Environment User Variable:
Java 7
MAVEN_OPTS -Xmx512m -XX:MaxPermSize=128m
Java 8
MAVEN_OPTS -Xmx512m
The JDK 8 HotSpot JVM is now using native memory for the representation of class metadata and is called Metaspace.
The permanent generation has been removed. The PermSize and MaxPermSize are ignored and a warning is issued if they are present on the command line.
-XX:MaxPermSize=size
Sets the maximum permanent generation space size (in bytes). This option was deprecated in JDK 8, and superseded by the -XX:MaxMetaspaceSize option.
-XX:PermSize=size
Sets the space (in bytes) allocated to the permanent generation that triggers a garbage collection if it is exceeded. This option was deprecated in JDK 8, and superseded by the -XX:MetaspaceSize option.
In JBoss EAP 6.4, right click on the server and open launch configuration under VM argument you will find
{-Dprogram.name=JBossTools: jboss-eap" -server -Xms1024m -Xmx1024m -XX:MaxPermSize=256m}
update it to
{-Dprogram.name=JBossTools: JBoss 6.4" -server -Xms512m -Xmx512m}
this will solve your problem.
I got similar message when running command line mvn (version 3.3.3) on Linux with Java 8.
By opening maven script /$MAVEN-HOME/bin/mvn, found the following line
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
Where $MAVEN_PROJECTBASEDIR by default is your home directory.
So two places you can take a look, first is file $MAVEN_PROJECTBASEDIR/.mvn/jvm.config if it exists. Secondly look at files possibly set up the environment variable MAVEN_OPTS. Candidate files are .bashrc, .bash_profile, .profile and those files included by them such as /etc/profile, /etc/bash.bashrc
I located
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
in .bashrc in my system, change it to
export MAVEN_OPTS="-Xmx512m"
issue resolved
in case some one still get this kind of message. Its happen because you add JVM argument when running maven project. Because it is related with maven you can check your pom.xml file on your project.
find this line <argLine>...</argLine>, on my project I also have argument below
<argLine>-Xmx1024m -XX:MaxPermSize=512m -XX:+TieredCompilation -XX:TieredStopAtLevel=1</argLine>
you should replace MaxPermSize argument as -Xms123m -Xmx123m, since MaxPermSize is already deprecated and wont take any effect on your JVM config :
<argLine>-Xms512m -Xmx512m -XX:+TieredCompilation -XX:TieredStopAtLevel=1</argLine>
Please to solve this problem we just have set installed JDK path in
standalone.conf
file which under the bin folder of JBoss\Wildfly Server. To solve this we do the following steps:
Open the standlone.conf file which under JBoss_or_wildfly\bin folder
Within this file find for #JAVA_HOME text.
Remove the # character and set your installed JDK path as
JAVA_HOME="C:\Program Files\Java\jdk1.8.0_65"
Hope this will solve your problem
Thanks
For Eclipse users...
Click Run —> Run configuration —> are —> set Alternate JRE for 1.6 or 1.7

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize

When building a Java 8 project with Maven:
mvn clean package
I get this message:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
How to remove this message?
Compatibility Guide for JDK 8 says that in Java 8 the command line flag MaxPermSize has been removed. The reason is that the permanent generation was removed from the hotspot heap and was moved to native memory.
So in order to remove this message
edit MAVEN_OPTS Environment User Variable:
Java 7
MAVEN_OPTS -Xmx512m -XX:MaxPermSize=128m
Java 8
MAVEN_OPTS -Xmx512m
The JDK 8 HotSpot JVM is now using native memory for the representation of class metadata and is called Metaspace.
The permanent generation has been removed. The PermSize and MaxPermSize are ignored and a warning is issued if they are present on the command line.
-XX:MaxPermSize=size
Sets the maximum permanent generation space size (in bytes). This option was deprecated in JDK 8, and superseded by the -XX:MaxMetaspaceSize option.
-XX:PermSize=size
Sets the space (in bytes) allocated to the permanent generation that triggers a garbage collection if it is exceeded. This option was deprecated in JDK 8, and superseded by the -XX:MetaspaceSize option.
In JBoss EAP 6.4, right click on the server and open launch configuration under VM argument you will find
{-Dprogram.name=JBossTools: jboss-eap" -server -Xms1024m -Xmx1024m -XX:MaxPermSize=256m}
update it to
{-Dprogram.name=JBossTools: JBoss 6.4" -server -Xms512m -Xmx512m}
this will solve your problem.
I got similar message when running command line mvn (version 3.3.3) on Linux with Java 8.
By opening maven script /$MAVEN-HOME/bin/mvn, found the following line
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
Where $MAVEN_PROJECTBASEDIR by default is your home directory.
So two places you can take a look, first is file $MAVEN_PROJECTBASEDIR/.mvn/jvm.config if it exists. Secondly look at files possibly set up the environment variable MAVEN_OPTS. Candidate files are .bashrc, .bash_profile, .profile and those files included by them such as /etc/profile, /etc/bash.bashrc
I located
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
in .bashrc in my system, change it to
export MAVEN_OPTS="-Xmx512m"
issue resolved
in case some one still get this kind of message. Its happen because you add JVM argument when running maven project. Because it is related with maven you can check your pom.xml file on your project.
find this line <argLine>...</argLine>, on my project I also have argument below
<argLine>-Xmx1024m -XX:MaxPermSize=512m -XX:+TieredCompilation -XX:TieredStopAtLevel=1</argLine>
you should replace MaxPermSize argument as -Xms123m -Xmx123m, since MaxPermSize is already deprecated and wont take any effect on your JVM config :
<argLine>-Xms512m -Xmx512m -XX:+TieredCompilation -XX:TieredStopAtLevel=1</argLine>
Please to solve this problem we just have set installed JDK path in
standalone.conf
file which under the bin folder of JBoss\Wildfly Server. To solve this we do the following steps:
Open the standlone.conf file which under JBoss_or_wildfly\bin folder
Within this file find for #JAVA_HOME text.
Remove the # character and set your installed JDK path as
JAVA_HOME="C:\Program Files\Java\jdk1.8.0_65"
Hope this will solve your problem
Thanks
For Eclipse users...
Click Run —> Run configuration —> are —> set Alternate JRE for 1.6 or 1.7

Difference in JVM heap size allocation between Netbeans 7.0.1 and 7.1?

I have a java program that I developed using Netbeans 7.0.1 to parse and save large CSV files. Because of the size of the CSV files I needed to increase the heap size of the JVM. In 7.0.1 I set the heap size to use 4GB of my 8GB on my system using the -Xmx4096m specification under Project ->Properties -> VM Options in Netbeans. It worked fine in 7.0.1.
Now I'm trying to run it in Netbeans 7.1 and I'm getting the following for output from Netbeans
Could not create the Java virtual machine.
Invalid maximum heap size: -Xmx4096m
The specified size exceeds the maximum representable size.
Java Result: 1
I've changed nothing from default in Netbeans when I get this error.
I figured that maybe in 7.1 they had "locked" the heap size in the netbeans.config file so I went there.
First I tried this:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Xmx4906m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true"
That gives me a Failed to create JVM popup at Netbeans splash screen.
Then I tried this:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=4096m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true"
Netbeans seems to like that better as the load bar will go all the way to "Done loading modules." but then it just hangs on the splash screen. I let it hang there for 5 mins before killing it.
This isn't a show stopper for me since I can still run it fine under 7.0.1 but was wondering if anyone had a solution to this. Seems like it should be an easy fix but I'm just overlooking something?
Thanks for your time.
It looks like you installed your NetBeans with a 32-bit java.exe, Edit your netbeans.conf in C:\Program Files (x86)\NetBeans 7.1\etc\ or C:\Program Files\NetBeans 7.1\etc\
and make sure it says (replace jdk1.7.0_03 with the version you actually intend on using):
...
# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="C:\Program Files\Java\jdk1.7.0_03"
...
and not
...
# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="C:\Program Files (x86)\Java\jdk1.7.0_03"
...
note that the "(x86)" in Windows means 32-bit, or just edit your project and pick a 64-bit JVM. You may have to add your 64-bit JVM to Tools->Java Platforms. Of course if you aren't using Windows the specifics will be different but it will still be a 32-bit vs 64-bit issue.
This situation usually arises when someone wants to use a newer JVM but they accidently install the 32-bit version instead of the 64-bit. Also note: you can configure your project to run/debug in a 64-bit JVM while NetBeans itself is running in a 32-bit JVM, so you don't actually have to modify netbeans.conf to make your project capable of allocated 4GB.
In summary:
Make sure you have a 64-bit JDK installed
Make sure your 64-bit JDK is listed in your Java Platforms in NetBeans
Make sure Your Project->Properties->Libraries->Java Platform is set to the 64-bit JDK you want to use.

Categories