Quickly create Jar artifact for application

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:

This entry was posted in New Features and tagged . Bookmark the permalink.

35 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


  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:

    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:

    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:

    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.

    • Jon says:

      I too would need this function. Things like config files, which are part of the project, but should be outside of the jar 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?

  15. jack says:

    I am getting the error “Failed To load Main-Class manifest attribute from jar”.

  16. Dinuka says:

    Thanx a lot for sharing your knowledge.. this article has saved my time…!!

  17. Josh says:

    java test.jar “Error: Could not find or load main class test.jar”
    java -jar test.jar “no main manifest attribute, in test.jar”

    Runs just fine from the IDE. All that confusion just to build a non-functional “executable” jar file…

  18. Josh says:

    To all those having problems, I finally figured out why IntelliJ can fail at making a working executable jar:

    In my case, it was because IntelliJ was extracting all my dependencies into the output jar (good), which ended up overwritting the /META-INF/MANIFEST.MF file with something from one of my dependencies (bad). I had to open up the jar and copy in the real MANIFEST.MF from the location indicated in the “Manifest File” property that is automatically set in that artifacts page under Project Structure”.

  19. I like the valuable info you provide in your articles. I’ll bookmark your weblog and check again here frequently.
    I am quite sure I’ll learn many new stuff right here!
    Good luck for the next!

  20. JarConfused says:

    I’ve been Googling for hours, on this. All Intellij instructions for generating a jar, are dedicated to generating an artifact-style executable jar. I know how to do that, and it’s worked fine, aside from sometimes having to manually remove Kitfox.* files.

    But how in the world, can you coax Intellij to generate a jar WITHOUT a main class? It’s easy to do from the command line, but it’s not clear how to do it, within the Intellij project.

    All the class files in the project are solid, they compiled fine. But how in the world, can we generate just a basic jar, from within Intellij without a main attribute in the manifest?

  21. Nikolay Chashnikov says:

    IDEA doesn’t generate main-class attribute itself so if you get it in your jar file it means that you have manifest.mf file with this attribute in your sources.

  22. IntelliJ Novice says:

    I have multiple files (Java classes with main) in my package. I want to create separate jar files for each java class. Right now I can create a jar with one name – main project name. Please help. Thanks

  23. Nikolay Chashnikov says:

    IntelliJ Novice,
    if you need to create separate jars for several java classes it would be better to move these classes to separate modules. After that you can use ‘Jar -> From module with dependencies’ action to create separate artifacts for these modules.

  24. Hadeser says:

    please update blog !!!!

  25. ChipOfTheOldBlock says:

    Is there a way to create a Jar file that includes just a couple of classes (selected by user). Usually, we need to do this to provide fixes (instead of releasing the whole app)

  26. Peter says:

    > In my case, it was because IntelliJ was extracting all my dependencies into the output jar (good), which ended up overwritting the /META-INF/MANIFEST.MF

    That happened to me as well. I tried navigating to the generated manifest file in project and ‘Package file’ it and also changed the order of packages in jar (you need to disable sorting for that) and it seems disappeared =)

  27. Henry says:

    the intellij make the lib.jar to class file,not the original jar lib,how can we do it as eclipse “Extract required libraries into generated jar” ?

  28. Nikhil says:

    I am getting this error while running the jar created using intellij
    “Exception in thread “main” java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”
    But when a jar for the same code/project is generated using eclipse it works fine.

  29. Roy Truelove says:

    I’ve given up on getting an executable jar w/ Intellij. Two issues, one already mentioned:

    1) Intellij creates a manifest for you but it gets overridden by the manifests in the dependent libraries. You should create your own manifest and put it in src/main/**resources** and not src/main/java

    2) It doesn’t handle this: https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer


  30. CapitanShinChan says:

    How can I generate a Jar from .java files, if I don’g have a main class?

    I don’t want to run this jar separately, it’s going to be load in another program.

    This seems a pretty basic operation but I can’t get it done in IntelliJ Idea (using version 15).

    • Nikolay Chashnikov says:

      if you want to create a jar without main class you can just use the action described in this blog post (JAR -> From Module with Dependencies), though the UI is slightly different in the latest version (the blog post is 5 years old). ‘Main Class’ field is optional and you can leave it empty. If it doesn’t work for you please file a bug in our issue tracker.

  31. Terry says:

    I’m in the process of moving from NetBeans to IntelliJ, because it is used by those making several important projects I’m involved with. It is beautiful, but I’m amazed that I still can’t get a simple project .jar file out of it! I want to run under Spark, and I really don’t want to have to import it into NetBeans just to get a reasonable damn .jar

    Looking at the comments above, for literally years, I can’t image why the developers have not addressed this issue. Does this work in the “professional” version?

  32. Maxim says:

    Hi there! For all who have a problem “no main manifest attribute, in “. All you need is to add to your Artifact a folder with name “META-INF” with content of a folder with correct MANIFEST.MF file and locate this folder at the top of jar content. So for case of Idea 13.1.3 all you need is to open Project Structure -> Artifacts -> activate your artifact -> in window “Output Layout” click on “Create Directory”, name it “META-INF”, then select it and click on “+” and choose “Directory content” – navigate to your directory with correct manifest file. And then just disable sorting and “Move up” this new “META-INF” directory at the top of files hierarhy. That is all, hope it will save your time:)

Leave a Reply

Your email address will not be published. Required fields are marked *