0

I am using IntelliJ and I would like to package a library I found into a jar for my project. Said library was found online and only contains java files without a main class. Before someone flags this for being a duplicate, it is not. All other questions are with projects that have a main class. I tried following https://stackoverflow.com/a/45303637/10002144, but it does not work because I get to a point where it says "META-INF/MANIFEST.MF file not found in 'libname.jar'. I also tried making a gradle project and building it, but it simply creates a jar that is only 297 bytes long, so obviously that doesn't work.

What can I do in my case?

ThomasFromUganda
  • 380
  • 3
  • 17
  • [https://stackoverflow.com/questions/32008856/how-to-create-a-jar-without-manifest-file-and-main-class/32009146] Take a look at this. This might be what you're looking for. – Ashish Jul 07 '19 at 04:09
  • A `MANIFEST.MF` can list other useful information (like build date, API version etc.) without having a main class specification. Try supplying a manifest. – Andrew Thompson Jul 07 '19 at 05:07
  • @Ashish This is a very random library that came with a product we bought. It's an API for a specialized cable used for airplanes. They just include a folder with 10 java classes with the product, which is what I am trying to package. – ThomasFromUganda Jul 07 '19 at 12:41
  • @ThomasFromUganda Okay. I understand that. The link that I mentioned in my comment enables you to package all the files in the directory. Please take a note of this comment made by the user Stultuske : "a .jar file is nothing but a zip file with a different extension. a manifest and main class are only needed if you want to run your jar as executable, but a jar can just as well be used as a library of classes, used after importing in a project." So, if you can compile all those classes, you'll get .class files; zip it and change the extension to .jar, it should hopefully work. – Ashish Jul 08 '19 at 02:20

1 Answers1

0

What are you using as a package resolver? For maven, gradle, sbt projects you can simply run the package instruction (i.e. mvn package) and it will jar your project regardless of a main class.

Adam
  • 152
  • 1
  • 1
  • 6
  • That's the issue. I tried with gradle and without gradle and I keep getting a 297 bytes long jar file, which is obviously too small. – ThomasFromUganda Jul 07 '19 at 12:40
  • @ThomasFromUganda maybe it's because the jar has dependencies that you're not resolving into the built jar itself. see https://www.baeldung.com/gradle-fat-jar – Adam Jul 17 '19 at 01:31
  • No, All I have is 8 java file with no main. There are no dependencies or anything. – ThomasFromUganda Jul 19 '19 at 18:44
  • The only way to do this is to create a fake mock main class and include it with the jar files and build: https://stackoverflow.com/questions/14506704/how-to-generate-jar-file-with-no-main-method. – Adam Jul 20 '19 at 03:17
  • Thanks for replying. What does work is using the command line to make a jar. `jar -cvf JarFileName.jar FolderName`. This works fine, but IntelliJ doesn't want to do such a simple task, – ThomasFromUganda Jul 21 '19 at 15:49