Build Jar with a single class and no Main method

I'm building components for Solr which leverages Solr's plugable architecture of just droping in Jar files containing a single class (with no main method in them).

Other than using ANT, is there a way in IntelliJ to build a Jar which contains just a single class (with no Main method)?

When I follow the on-line documentation, using Project Structure / Artifacts, IntelliJ prevents me from defining an artifact as having only a Java class with no Main method.


You can use 'Create Directory' button in 'Output Layout' tree in the artifact editor to create desired packages in the jar and then use '+' -> File
class-files into that package. However it would be better to extract classes which need to be packed to a jar into a separate module and add this
module to the artifact as a whole. This way you can ensure that these classes doesn't have dependencies which aren't included in the jar and also
instruct IDEA to compile these classes whenever the artifact is built. Note that extracting a module doesn't necessary mean that you need to
physically move these classes into a separate directory. If all these classes are located under a single package you can create a module with a source
root pointing to the corresponding package and specify 'package prefix' for this source root accordingly.

Nikolay Chashnikov
Software Developer
JetBrains, Inc
"Develop with pleasure!"


Thanks for this hint. This is what I really needed. In my case I needed to share some POJO classes from my JAVA Web App with an android project.


Please sign in to leave a comment.