5

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
BSMP
  • 4,596
  • 8
  • 33
  • 44
Jerry
  • 669
  • 8
  • 17

1 Answers1

13

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.

Jerry
  • 669
  • 8
  • 17
  • 3
    Actually, the rule is, the `-jar` option must come last. Everything that follows that are arguments to be passed to the Java program, not options for the JVM. – C. K. Young Aug 20 '13 at 03:05
  • https://issues.jenkins-ci.org/browse/JENKINS-12521?focusedCommentId=161466&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-161466 – Christopher Roscoe Dec 03 '13 at 10:28
  • Also related, because I just suffered similar issues: https://issues.jenkins-ci.org/browse/JENKINS-57271 – Thomas Keller May 01 '19 at 11:35