28

Is it possible to run a Java app which doesn't contain MANIFEST.MF file? Of course, there's static main method,just lacks manifest file. And the app is depending on several external .jar files.

If is this possible, how to do that?

4 Answers 4

30

It is possible, you can specify the class to run from the command line:

java -cp yourJar.jar your.main.Class

Same question here:

How to run a class from Jar which is not the Main-Class in its Manifest file

7
  • 1
    It's strange that the above works but java -jar your.main.Class does not. Mar 17, 2018 at 2:22
  • @backslash, by running above code if getting Error like : "Could not find or load main class" What to debug ? May 29, 2018 at 9:09
  • @IshitaShah It means that the class could not be found or is not a main class. Did you check the class name and the package name? Are you 100% sure your class has a correct main method definition?
    – BackSlash
    May 29, 2018 at 12:30
  • 1
    @IshitaShah The class you run must have a main method. It's the first method run by the JVM, if you don't have that your app won't run. That's why you get that error.
    – BackSlash
    May 29, 2018 at 12:38
  • 1
    @IshitaShah TestNG has a completely different way of running tests, you need to go through their documentation to learn how to run tests from command line. I'm not familiar with TestNG, so I can't help.
    – BackSlash
    May 29, 2018 at 13:20
12

You can also add the manifest, with the following command:

jar  -uvfe  your.jar foo.bar.Baz
java -jar your.jar        # tries to run main in foo.bar.Baz
3

Of course! Just use this:

java -cp MyJar.jar com.example.Main
3

Yes , use this

java -cp myJar.jar package.className

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.