1

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?

2
  • It is possible, because maven's assembly plugin works that way. Commented 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... Commented Oct 3, 2011 at 17:16

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.