How should I pass a System Property options to my jar file?

Viewed 1786

I have written a small application to parse a large XML file using SAX with Intellij.

I pass -DentityExpansionLimit=0 option to my application by going to Run\Edit Configurations... and set VM options.

It works perfectly when I run the application with Intellij, but when I create the artifact with intellij it doesn't work and I get the error which needed to set that option. This is obvious that the option didn't pass to the created jar file.

How should I achieve this goal?

Is there any command that I create with a batch file or something to set this option for my user? Is there any setting file that I can modify to set this option for my machine? (I use windows 10)

2 Answers

Usually, to send system properties to a jar, the command is something like that:

java -DentityExpansionLimit=0 -jar thejar.jar

You are mixing up two things here:

  • the JVM command line command, and the fact that you can pass arguments to your application, or properties to the JVM itself
  • your deployment artefact (probably a JAR file)

Meaning: It seems like you want to either pass command line arguments (to some main function) or properties to your application. But the JAR file doesn't have support for that.

JAR files are just a container of class files. You can add some META information via the manifest (which class to run), but that is about it. You can't magically push your IntelliJ "runtime configuration settings" into the JAR.

In other words: IntelliJ has no way of putting these values into your JAR. When you invoke java -jar Your.jar ... then you (or some other tooling) has to add the required values to the command line.

Related