0

I try to create a library by creating a fat jar with maven in IntelliJ. However, in that library I don't need main class because all methods and classes were tested with unit tests. So, the main class is simply there because all java programs need it and if I delete it I would get an error. How could I create a jar with dependencies (fat jar or uber jar) without main class?

I tried to use it with maven assembly plugin.

JPA
  • 11
  • 2
  • Feed it lots of other jars? – K.Nicholas Dec 23 '22 at 17:04
  • Maven Shade doesn't care if there's a main class – g00se Dec 23 '22 at 18:21
  • Fat jars cannot be used as libraries. – Thorbjørn Ravn Andersen Dec 23 '22 at 18:22
  • @ThorbjørnRavnAndersen I don't see why not but having said that, something will have to use that library, which implies at least two jars. If there's more than one, it really defeats the usual point of a fat jar – g00se Dec 23 '22 at 18:24
  • @g00se Depends on how the jar is created. If it is anything but all the files in all the jars repackaged as a single jar, like jars-in-jar, the JVM (and therefore Maven) does not understand them unless you bring in a special classloader. This is what Spring Boot does, but that does not apply when just put on the classpath. – Thorbjørn Ravn Andersen Dec 23 '22 at 19:15
  • You can actually create fat jars by just zipping a lot of classes together. That's precisely how I used to do it in a rather makeshift way with Ant – g00se Dec 23 '22 at 22:27
  • Doing it with Maven creates an additional problem that if there is another dependency on an included library (possibly transitive), this is invisible to Maven’s resolver and could result in different versions of the same classes on the classpath. – Tim Moore Dec 24 '22 at 00:24
  • The Maven Shade Plug-in works around that problem by rewriting the package names. – Tim Moore Dec 24 '22 at 00:26
  • Using the maven-assembly-plugin should work. If you don't want a main class, then don't specify one. Otherwise, please provide a [mre] that show what you're doing and provides sufficient details about what is going wrong. – Mark Rotteveel Dec 24 '22 at 12:20

0 Answers0