multiple jar Artifacts per Module

Hi All
I need to setup a module so that I can build multiple different jar files from it's compile output.

For example, suppose I have the following existing src structure (and am creating a project using it):



















So I create IDEA modules for moduleA and moduleB, and give them the respective content root of java/src.

Now suppose for moduleA I need to create a food.jar and a plants.jar, each containing only the classes for each package branch (and maybe include util just for kicks).

I can't seem to figure out how to do this (is it even possible?) because I can selective choose from the compile output when I include that in the jar Artifact.  Nor can I create multiple IDEA modules for moduleA as IDEA only allows one module per Content Root.

Note that I cannot re-arrange the src file structure, this is for an already existing project (with an already in place ant build)
Any ideas or suggestions?


Comment actions Permalink

Surely I can't be the only one with this issue?
Is the question not clear?  Do I need to provide more info/detail?

All I really want is to do something like Ant has in it's jar/fileset tasks:

<jar destfile="lib/fubar.jar" manifest="build/MANIFEST.MF" >

<fileset dir="build/java">

<include name="com/foo/**/*"/>

<include name=">

<include name="icons/**>

<exclude name="com/foo/not/these/classes/**/*"/>

<exclude name="com/foo/or/these/classes/**/*"/>



Comment actions Permalink

You can do it but it will be a pain for sure. My suggestion is use the facilities of Ant or Maven to build the artifact over configuring Intellij. If you must do it from Intellij it's going to require building the artifact structure manually using Intellij's Artifact editor. Start with an empty jar file then create the top-level directories using the Create Diretory option in the right-click menu. Eventually you will need to add the Directory Content where your class files are loaded but you will need to create the top-level packages yourself since you want to exclude some of the package directories. Create an artifact for each jar file you want to build from your classes and include only the package directories you want in each jar.


Comment actions Permalink

I guess I'll just write Ant targets to do this.  While it would be nice to do inside Intellij it is not required.  I just wanted to make the code-build-deploy-test development cycle a little quicker but it seems that it is not worth the effort.


Comment actions Permalink

If you need to create a jar from a package it would be better to extract that package into a separate module. In this way you can ensure that there
are no incorrect dependencies between packages (e.g. classes from 'util' package don't depend on classes from 'food').

You can extract 'food' package into a separate module without changing the source directory structure. Just create a new module and specify
a_project/moduleA/java/src/com/foo/food as its content root. IDEA will automatically exclude that directory from moduleA. Also it should suggest you
to mark the new content root as a source root for the new module with correct package prefix.

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

Comment actions Permalink

Thanks for the answer!
This solution has solved my dilemma.

Comment actions Permalink

Since this is the top answer on google:  it's actually crazy easy to create two jars from one module.  See this Stackoverflow question for the exact steps.


Please sign in to leave a comment.