I've specified the main class and classpath for a java program in the .jar file manifest, but occasionally I want to run a different class from the one specified by the Main-Class attribute. Can I get java to launch this class while still pulling the classpath from the manifest, so that I don't have to specify the whole thing on the command line with -cp?
- It is possible, because maven's assembly plugin works that way.Kevin– Kevin2011-10-03 16:33:24 +00:00Commented Oct 3, 2011 at 16:33
- why dont u provide a batch/shell script to run the jar file for u and let that script decide what to do...Kowser– Kowser2011-10-03 17:16:59 +00:00Commented Oct 3, 2011 at 17:16
Add a comment |
1 Answer
Just put the jar file on the command line with -cp; Java will then observe the classpath attribute within the manifest, even though you're not using -jar:
java -cp app.jar MyOtherClass 1 Comment
Neil Traft
Finally got the chance to confirm... this works! It will append the
Class-Path attribute to the classpath just the same as using the -jar option.