Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected java.lang.IllegalArgumentException when calling a jar file

I am trying to run the Jenkins war file with some additional java options as suggested here, 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
like image 964
Jerry Avatar asked Aug 20 '13 02:08

Jerry


People also ask

How do you handle Java Lang IllegalArgumentException?

Since IllegalArgumentException is an unchecked exception, you don't have to handle it in your code: Java will let you compile just fine. In many cases, instead of trying to catch IllegalArgumentException , you can simply check that a value falls in the expected range before passing it to a method.

What does illegal argument exception mean?

An IllegalArgumentException is thrown in order to indicate that a method has been passed an illegal argument. This exception extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM).


1 Answers

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.

like image 84
Jerry Avatar answered Sep 17 '22 18:09

Jerry