Take the 2-minute tour ×

I have created a jar file usign maven2 build. I am trying to run that jar file using the command:

java -jar sample.jar com.app.Test

Test being the class which is having the main method. But i am getting this exception:

Exception in thread "main" java.lang.NullPointerException
        at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Can any one help me to solve this exception and run the jar file?

Thanks in advance.

share|improve this question
Did you include a MANIFEST file in your jar that specifies the main class to run? See: download.oracle.com/javase/6/docs/technotes/guides/jar/… –  a_horse_with_no_name Nov 19 '11 at 7:39
Maybe the manifest file is broken? Can you open the jar file and check that the main class is properly defined in META-INF/Manifest ? –  Thilo Nov 19 '11 at 7:39
can you run it outside of the jar and it works? –  pajton Nov 19 '11 at 7:39
Did you create a manifest file: docs.oracle.com/javase/tutorial/deployment/jar/… –  amb110395 Jul 26 '13 at 20:39

3 Answers 3

up vote 7 down vote accepted

If you want to run the Test class, you should use

 java -cp sample.jar com.app.Test

This way, you add the jar to the classpath and then run the specified main class.

What java -jar does is that it executes a runnable jar file (which defines its own main class in the manifest file). Any parameters after that would not be used to specify the class, but end up in the String array passed to the main method.

So if you have a properly constructed runnable jar file, it should just be

java -jar sample.jar 
share|improve this answer
Thanks Thilo, how to specify entry class in manifest file at the time of building the jar? –  user972590 Nov 19 '11 at 7:48
Main-Class: com.app.Test download.oracle.com/javase/6/docs/technotes/guides/jar/… –  Thilo Nov 19 '11 at 7:49
Or, using Maven (which can also bundle in all dependencies, which is something you want): stackoverflow.com/questions/2022032/… –  Thilo Nov 19 '11 at 7:50

If you are using Maven, you may need to use maven's install command. You can find the format here http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

share|improve this answer

Looks like you do need a manifest and a Main-Class attribute, if you don't have one. If you are using java 7 a bug is filed here http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7067922

share|improve this answer

Your Answer


