简体   繁体   中英

main method not found using One-Jar

I am using One-Jar to combine my application and its dependencies into one jar file. I used the command line approach step by step. However, when running the jar file with java -jar one-jar.jar I recieve the following

error:

Exception in thread "main" java.lang.ClassNotFoundException: com.webtest.hc.Main
    at com.simontuffs.onejar.JarClassLoader.findClass(JarClassLoader.java:713)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at com.simontuffs.onejar.JarClassLoader.loadClass(JarClassLoader.java:630)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.simontuffs.onejar.Boot.run(Boot.java:336)
    at com.simontuffs.onejar.Boot.main(Boot.java:168)

Here is my boot-manifest.mf :

Manifest-Version: 1.0

Main-Class: com.simontuffs.onejar.Boot

One-Jar-Main-Class: com.webtest.hc.Main

and i followed the exact same instruction as it is in the One-Jar website

Your JAR is packaged incorrectly. The message error says Java can't find the One-Jar loader, which is com.simontuffs.onejar.Boot so you somehow ended up with a malformed archive even if you tried to follow the instructions on the One-Jar site.

How do I know that the JAR is malformed?

Well, from the JVM message we can guess you miss the following files if you try and open the JAR with a ZIP viewer:

META-INF/MANIFEST.MF
com/simontuffs/onejar/Boot.class
com/simontuffs/onejar/Handler$1.class
com/simontuffs/onejar/Handler.class
com/simontuffs/onejar/JarClassLoader$ByteCode.class
com/simontuffs/onejar/JarClassLoader.class
boot-manifest.mf

How do I fix the packaging process?

It depends and we don't have the sources so can't tell. As a personal recommendation, I use Gradle as a build tool and it's well integrated with IDEs (Eclipse and Intellij) and Capsule , an alternative to One-Jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM