Unexpected java.lang.IllegalArgumentException when calling a jar file

command-line, command-line-arguments, jar, java

Solution

My problem, pointed out by my co-worker, is that I was specifying the jar file before the options:

nohup nice /usr/bin/java -DJENKINS_HOME=/opt/jenkins/CI -Dorg.apache.commons.jelly.tags.fmt.timeZone=America/New_York -Djava.awt.headless=true -jar jenkins.war -XX:MaxPermSize=2048m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

It should have been:

nohup nice /usr/bin/java -DJENKINS_HOME=/opt/jenkins/CI -Dorg.apache.commons.jelly.tags.fmt.timeZone=America/New_York -Djava.awt.headless=true -XX:MaxPermSize=2048m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -jar jenkins.war

Simple mistake, but (aside from the documentation, which I unfortunately glossed over), I haven't seen anywhere that XX options must precede the jar file on the java command line.

Problem

I am trying to run the Jenkins war file with some additional Java options as suggested in this answer, but I get the exception: ``` Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at Main._main(Main.java:288) at Main.main(Main.java:98) Caused by: java.lang.IllegalArgumentException: Multiple command line argument specified: -XX:+CMSClassUnloadingEnabled at winstone.cmdline.CmdLineParser.parse(CmdLineParser.java:68) at winstone.Launcher.getArgsFromCommandLine(Launcher.java:391) at winstone.Launcher.main(Launcher.java:359) ... 6 more ```

Original source

Related problems