1

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

Tiara
  • 59
  • 6
  • Are your files in root/main and root/lib? (Root is the projectfolder) – Charlie Jun 26 '18 at 16:23
  • @thomas yes. my dependencies are in root/lib and my application.jar is in main which has this package : com/webtest/hc – Tiara Jun 26 '18 at 16:30

1 Answers1

0

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.

Raffaele
  • 20,627
  • 6
  • 47
  • 86
  • Thank you for your help. But I unziped the JAR and I have all the class files that you mentioned – Tiara Jun 26 '18 at 16:59
  • It can't be. Upload your JAR somewhere (Google Drive, Dropbox, whatever) and share the link, so I can tell you what's wrong with it – Raffaele Jun 26 '18 at 17:05
  • https://drive.google.com/drive/folders/1zyRO9WWrWmpydEBXEVoIjkroDU8XZgJE – Tiara Jun 26 '18 at 17:46
  • Upload the JAR. Debugging screenshots is an art I still don't have the privilege to manage – Raffaele Jun 26 '18 at 17:51
  • Thank you Raffaele for looking at my screenshots. It's for my job I'm not sure if I am allowed to. – Tiara Jun 26 '18 at 17:53
  • If you are allowed I can try to help. If you are not, I can only tell you that from the screen it *should* work, but somehow it *doesn't*. That *somehow* will remain a mystery to me (I hope less-than-so for you) – Raffaele Jun 26 '18 at 17:54
  • From the screen I see there are at least two different versions of your JAR (webmain-2.6.0.jar in the root and webmain-0.7.2.jar in `main/`) and there are program classes in `main/com/webmain/hc/`. It doesn't work this way – Raffaele Jun 26 '18 at 18:03
  • webmain-2.6.0 in what is the final jar product I unzipped it that's why its in the folder. But I got the One-Jar work ! but when I add it as an external jar to my eclipse project, it does not show the content of the inside jars ? Is it how it is supposed to be ? – Tiara Jun 27 '18 at 13:39