0

I have a scenario where I need to make a dummy executable jar with Main-Class from a different jar which is in classpath ( i.e., main class is not in the dummy jar). Is that possible to achieve this?

This is because the jar which is having the main class is not an executable jar but same time I don't want to tamper with it since it is a third-party jar, while as per our standard application invoke scripts we should use an executable jar to invoke the application. Hence I created that dummy jar with Main-Class in it. But still it's giving:

Error: Could not find or load main class

eg : dummy.jar manifest entries:

Main-Class: com.thirdparty.jar.MainClass
Class-Path:thirdpartyapp.jar

Here the com.thirdparty.jar.MainClass is inside thirdpartyapp.jar.

Thanks in advance :)

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Are both jars in the same directory? – erickson Mar 26 '14 at 04:22
  • Have you consider putting a `main` class in your `dummy` jar that just executes the `com.thirdparty.jar.MainClass` of the third party jar...basically a proxy launcher...? – MadProgrammer Mar 26 '14 at 04:28
  • @erickson Yes both are in same folder. – user3048252 Mar 26 '14 at 04:30
  • @MadProgrammer Thats probably next option, but then I'm not sure how the thirdparty application is exiting from it's main class as i don't have the visibility to it. – user3048252 Mar 26 '14 at 04:32
  • Well, the main class does not have to be in the dummy jar. I just tested it out. This should work fine, and I suspect a typo. – erickson Mar 26 '14 at 04:34
  • Did you create the dummy jar with `jar`, or some `zip` tool? Because `jar` will do a tiny bit of validation on the manifest, which could help. – erickson Mar 26 '14 at 04:36
  • @erickson I did use ant jar task to create this jar with manifest attributes in it. So that shouldn't be a problem. So when you tested did you put the second jar in manifest classpath or you used the java -classpath second.jar? . Anayway let me check again , Thanks for the help – user3048252 Mar 26 '14 at 04:48
  • You can't use `-jar` and `-classpath` together; I used only `-jar dummy.jar`. And `dummy.jar` contains only a MANIFEST.MF with `Main-Class` and `Class-Path` (and version and created-by) attributes. It's just as you describe above, but it works. – erickson Mar 26 '14 at 05:19
  • Thanks @erickson I got this working, for a moment I thought it won't work with main-class from an another jar. The issue was with the Class-Path attribute I added in MANIFEST.MF . Thanks for the help. – user3048252 Mar 26 '14 at 07:57

0 Answers0