Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class –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?

like image 839
Java4Dummies Avatar asked Aug 03 '17 17:08

Java4Dummies


2 Answers

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

How visible the difference between those characters is depends on the used font.

See wikipedia on Dashes (unicode section)

like image 77
the8472 Avatar answered Sep 22 '22 15:09

the8472


JVM arguments considered hyphen to consider JVM arguments. If you are using MAC book, It could be easily delusional for view

A hyphen, -, separates words in phrases, as in “least-used product” and is used for line breaks in books and other matter.

An em dash, —, is used to set off a phrase—one in the middle of the sentence—that’s not quite a parenthetical, but it isn’t so germane as to be set off by commas. It’s also used as a sort of pause to emphasize something—something important at the end of a sentence.

An en dash, –, separates ranges for dates, numbers, and quantities—like 9–5 and January–August. It’s also used for certain kinds of connections, directions, and contrasts, such as standing in for “versus” in Lincoln–Douglas debates or in place name pairing like Alsace–Lorraine, where both are separate places being referred to together.

like image 24
Mohan Raj Avatar answered Sep 22 '22 15:09

Mohan Raj