[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.

background

When developing Java OSS and closed libraries in-house, I received such inquiries several times, so if I write it in Qiita at least, I think that it will solve itself by google. With a faint expectation.

The inquiry looks like this

pattern 1

The library documentation says that specifying -Dxxxx = yyyy enables the xxxx option, but it doesn't work. Is the library buggy?

Pattern 2

When launching a jar using the built-in tomcat (or Jetty, etc.), I've added -Dcom.sun.management.jmxremote and other JMX options to enable JMX, but even if I launch the application JMX port does not become LISTEN.

Do you need to adjust the parameters of the built-in Tomcat (or Jetty, etc.)?

It's not the library or the Servlet container that is buggy

Wrong command


java -jar zzzz.jar -Dxxxx=yyyy -Dcom.sun.management.jmxremote

At first glance, it looks like there is no problem, but it is as follows.

Correct command


java -Dxxxx=yyyy -Dcom.sun.management.jmxremote -jar zzzz.jar 

In short, it's about specifying the JVM argument after the -jar option: sweat:

By the way, with the java -help command, the order is clearly stated. Needless to say, [options] is the JVM option and [args] is the command line argument that the program handles.

$ java -help

how to use: java [options] <mainclass> [args...]
           (When executing a class)
Or java[options] -jar <jarfile> [args...]
           (When executing a jar file)
Or java[options] -m <module>[/<mainclass>] [args...]
       java [options] --module <module>[/<mainclass>] [args...]
           (When running the main class of a module)
Or java[options] <sourcefile> [args]
           (When running a single source file program)

Main class, source file,-jar <jarfile>、
 -m or--module <module>/<mainclass>The arguments that follow are as arguments to the main class
Will be passed.

...Below, abbreviated

Finally

JVM option doesn't work! ?? In that case, first check the command you typed before doubting others.

Recommended Posts

[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.
[WSL] Solution for the phenomenon that 404 is displayed when trying to insert Java with apt (personal memo)
Code used when you want to process Json with only the standard library in Java (improved version) gson unnecessary
I want to solve the problem that JS is not displayed properly unless reloaded when transitioning with Turbolinks: link_to
You also need to specify the host when debugging remotely with Java 9 or later
[Kotlin] The mapping library by reflection based on Java basically does not work with Kotlin.
Code to use when you want to process Json with only standard library in Java
When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3
When you want to explicitly write OR or AND with ransack
[For super beginners] The minimum knowledge you want to keep in mind with hashes and symbols
When you want to add a string type column with a limited length with the `rails generate migration` command
[For beginners] I want to automatically enter pre-registered data in the input form with a selection command.
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
What to do if Operation not permitted is displayed when you execute a command in the terminal
How to interact with a server that does not crash the app
A story that suffered from a space that does not disappear even if trimmed with Java The cause is BOM
I tried to make a program that searches for the target class from the process that is overloaded with Java