且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:无法找到或加载主类-Xmx1G

更新时间:2023-11-16 18:45:58

当你应该使用连字符减号(U + 002D)。

  -Xmx1G#不正确:破折号
-Xmx1g#正确:连字符减号




This is crazy; has anyone ever seen this before?

java –Xmx1G –Xms1G –XX:+UseG1GC -XX:+PerfDisableSharedMem -jar service-1.0-SNAPSHOT.jar
Error: Could not find or load main class –Xmx1G

I can do this:

java -jar service-1.0-SNAPSHOT.jar –Xmx1G –Xms1G –XX:+UseG1GC -XX:+PerfDisableSharedMem

but jmap -heap {PID} shows that it's ignoring the options completely. I've tried different variations:

java –XX:+UseG1GC -jar service-1.0-SNAPSHOT.jar –Xmx1G –Xms1G  -XX:+PerfDisableSharedMem
java -Xms1G -Xmx1G -jar service-1.0-SNAPSHOT.jar
java –xx:+useg1gc -jar service-1.0-SNAPSHOT.jar
java -server –XX::+UseG1GC -jar service-1.0-SNAPSHOT.jar`

I either get this error: Error: Could not find or load main class {OPTION}

Or it runs but ignores options.

Even java -XX:-UseConcMarkSweepGC -jar service-1.0-SNAPSHOT.jar is ignored:

jmap -heap 5879 
Attaching to process ID 5879, please wait... 
Debugger attached successfully. 
Server compiler detected. 
JVM version is 25.121-b13

using thread-local object allocation.  
Parallel GC with 8 thread(s)  
Heap Configuration:

MinHeapFreeRatio         = 0
MaxHeapFreeRatio         = 100
MaxHeapSize              = 4294967296 (4096.0MB)
NewSize                  = 89128960 (85.0MB)
MaxNewSize               = 1431306240 (1365.0MB)
OldSize                  = 179306496 (171.0MB)
NewRatio                 = 2
SurvivorRatio            = 8
MetaspaceSize            = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize         = 17592186044415 MB
G1HeapRegionSize         = 0 (0.0MB)

This is my JVM:

java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

This is happening on my Mac, and in Alpine Docker image. Any thoughts?

You used an en-dash (U+2013) when you should have used a hyphen-minus (U+002D).

 –Xmx1G # incorrect: en dash
 -Xmx1g # correct: hyphen-minus