Create Jar Library Without a Main Class

You can do it in few ways, for example from command line, from IDE, maven or other build tool, I describe 2 ways:

Command line:

You can create jar file from command line (without IDE), Here is reference: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html

jar cf jar-file input-file(s)

where jar-file is .jar file name you want and input-file(s) are files you want to put inside your library (can be a wildcard, e.g.: *.class)

Intellij Idea:

Create Artifact like in this article, but without specifying Main class http://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/

Then click Build > Build artifact > Build.

This works even if there is no Main class.


Use a build tool like Maven (no IDE dependencies but can be called from IDE for convenience) with the shade plugin to create an 'uber' JAR (that includes all needed dependencies into one final JAR for the project)...

"pom.xml"

...

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
       <!-- Run shade goal on package phase -->
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Documentation to Shade plugin:

https://maven.apache.org/plugins/maven-shade-plugin/