Recently i wanted to run a jar file where its Main entry is not specified in the MANIFEST file. I knew this can be done since i’ve done it before, but couldn’t remember how to do it. So as usual i googled it but could not find it.
The thing is that this is a scenario that can arise when there are multiple entry points (mutiple classes having static main methods) in the jar file.
Funny enough the solution was pretty simple. Eventhough one might think that you need to specify the extry point class and the jar file which it is contained, the truth is we look at that fact in a wrong angle. What we have to do is to specify the class name and then the class path which the jvm should look for relevant classes (thus our jar should be included in this path).
eg:
say we have a class foo.class (which has a static main method) and it is in the jar file bar.jar. Then to execute the jar using the static main method present in foo class
$ java -cp bar.jar foo
here the class name should be a fully qualified class name. You can add more paths to the -cp parameter seprating them from a “:”
Tags: Add new tag, cannot find entry point, main class not specified in manifest, multiple entry points in jar, multiple main classes in a jar file, multiple main methods in single jar, run a jar file, run custom class in jar file, run static main method in a jar, specify entry point in command line, specify main class in command line
December 3, 2008 at 9:00 am |
Thanks for your good idea!
March 23, 2009 at 4:36 pm |
great great solution. thanks.i searched this for my boss at work but wont mind if i have a relationship with u.i jst want to LEARN. u have my email.
April 1, 2009 at 1:43 pm |
thanks dude, just what I needed!
April 9, 2009 at 8:37 pm |
Thanks. Simple and to the point.
December 10, 2009 at 4:05 pm |
Succinct and to the point.
March 13, 2010 at 3:10 pm |
Nice work dude. Thanks, JIT (Just-In-Time) π
March 16, 2010 at 11:29 pm |
I’m having a tough time reading your site – the post isn’t being displayed the right way. Might possibly be my web browser (I’m still limited to using firefox 2.5), but I thought I’d give you a heads-up anyway just in case it’s something to do with your theme
October 24, 2010 at 6:16 am |
This is a very great post about wordpress. I surely love seeing and learning something new about it. Just subscribed and looking forward to read some more articles of yours. Good luck and I hope we can connect in one of these days.
November 24, 2010 at 4:42 am |
Thanks for your info. I’ve tried and succeed.
June 28, 2011 at 8:01 am |
Thanks for sharing this π
July 28, 2011 at 1:43 pm |
You made my day!!! Thanks!!!
August 11, 2011 at 6:15 am |
hi thank you very much for sharing this!! i want to learn something more, please send me mails if you find any new things
November 21, 2011 at 9:35 am |
thanks it helped me…..
December 26, 2011 at 10:21 pm |
Could you help me please?…is not working… (I’m in Windows XP):
C:\>jar -tf test.jar
META-INF/
META-INF/MANIFEST.MF
test/
test/MyClass.class
test/MyClass.java
C:\>java -classpath test.jar MyClass
Exception in thread “main” java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: MyClass. Program will exit.
C:\>
December 28, 2011 at 12:14 am |
It looks like the main class specified is wrong in the Manifest.MF file. Check to see if it is “test.MyClass” not just “MyClass” (the class name should be a fully qualified name)
HTH
Saminda
January 10, 2012 at 11:15 am |
Thanks, that was brilliant – just what I needed.
January 10, 2012 at 3:40 pm |
Thanks samindaw, β just what I needed.
February 20, 2012 at 8:46 am |
it doesn’t work at all
still can not find main class π¦
February 20, 2012 at 2:59 pm |
Hi Tony,
Whats the error you are getting? Try something simpler like a hello world and see if it works.
Saminda
May 16, 2012 at 9:41 pm |
Thank you SOOOO much!!!
December 24, 2012 at 7:42 am |
thank you… this was really helpful
December 27, 2012 at 11:58 am |
Hey, I still got an error even through this process..
C:\Program Files (x86)\JavaEmulator.com\KEmulator>java -cp KEmulator.jar emulato
r.Emulator
Exception in thread “main” java.lang.UnsatisfiedLinkError: C:\Program Files (x86
)\JavaEmulator.com\KEmulator\swt-win32-3346.dll: Can’t load IA 32-bit .dll on a
AMD 64-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at emulator.k.a(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.(Unknown Source)
at org.eclipse.swt.widgets.Display.(Unknown Source)
at emulator.ui.swt.aK.(Unknown Source)
at emulator.Emulator.main(Unknown Source)
I tried to run KEmulator in manny ways, but still can’t spot the error.. Please e-mail me asap… π
January 30, 2014 at 10:10 pm |
I know this is two years late, but here’s the issue: “Canβt load IA 32-bit .dll on a AMD 64-bit platform”.
Whatever KEmulator is, it referencing a 32-bit dll and you’re running on a 64 bit system. It’s not a java issue.