Quickly create Jar artifact for application

August 20th, 2010 by Nikolay Chashnikov

Since the last EAP build IntelliJ IDEA X provides an action to quickly create a single Jar artifact containing your modules with all dependencies. Just press ‘+’ button in the Project Structure dialog and select the appropriate item:

IntelliJ IDEA shows a dialog allowing you to customize the artifact:

After that you can build the Jar file using Build | Build Artifact menu item.

Note that by default all libraries are extracted to the target Jar. It became possible with addition of the new Extracted Directory element. Using such element you can extract a directory from a Jar file and place it into the output of your artifact:

Tags:

14 Responses to “Quickly create Jar artifact for application”

  1. duto Says:

    The path of manifest file is not update when we add or remove librairies or change directory of librairies (move) . It’s too domage :s

    Duto

  2. Michael Says:

    Having issue runnin JAR packaged via IDE. Get the following error

    “Exception in thread “main” java.lang.SecurityException: Invalid signature file”
    Any ideas what could be wrong?

  3. bear Says:

    in previous version of intellij it was easay to build a jar: now it is extremely non intuitive!
    the main problem is that I build a different jar for each module without dependencies!!!
    how do you do that?
    not obvious

  4. Denis Says:

    Please tell me where is created jar-file ??? I can not find it in the project folder.

  5. Nikolay Chashnikov Says:

    Denis,
    path to the jar file is specified in ‘Output directory’ in the artifact settings. By default it is under /out/artifacts directory.

  6. bipul Says:

    I am trying to create jar file. My project contains external csv files outside src folder that is essential for the project. But when running the jar file it seems as though they are not being involved.

    Any Idea

  7. Nikolay Chashnikov Says:

    bipul,
    files outside source roots aren’t included into jar file by default. However you can add them by hand: open the artifact settings in Project Structure dialog, press ‘+’ button under ‘Output Layout’ tab, select ‘File’ item and choose the desired files.

  8. Pepe Says:

    Hi, sorry for my english. How can i exclude a single file from the jar created in that way?

  9. Nikolay Chashnikov Says:

    Pepe,
    it isn’t possible now. However you can move that file to a separate module. This way you also ensure that other files don’t depend on the excluded file.

  10. Peter Says:

    When I try to run the jar executable, I get the ‘Could not find main class. Program will exit’ error. I used the browse tool to locate the Main Class, in Project Structure>Artifacts, but nothing I have tried putting in the Class Path text field seems to properly locate the class file (even leaving it empty).

    The main class is in the first package folder in src, so src/package1/MainProgram.
    The Main Class field reads package1.MainProgram
    I have tried relative and absolute path names for the Class Path, but nothing works. Currently it is: out/production/ProjectName/package1/

    What am I doing wrong?

  11. Edy Armendariz Says:

    Hello Team,

    I am also receiving this error when running the jar from the Terminal.

    “Exception in thread “main” java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”

    What am I doing wrong?

  12. Jon Wu Says:

    Solution for “java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”

    The problem is that one of the jars you extracted was signed. You could link the jars up instead of extracting them, but that’s not nice if you just want one jar file to run and share. I solved this with an ant post-processing task like this. Just change output.jar to the right name for your artifact.

  13. Jon Wu Says:

    Whoops, can’t paste XML into here. Here’s the ant build target: https://gist.github.com/3406283

  14. Jeff Says:

    I am now packaging my app to a jar and this is working great, thanks! Unfortunately I have a network copy step in my deployment to test servers and I would rather not send the entire groovy distribution every time I send a new iteration out. Is there a recommended way to send out an executable “my code only” jar which references the all in one?

Leave a Reply