Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multiple jar with different main in same project, IntelliJ

Im using IntelliJ 12 and I am trying to configure my project to produce a jar file for each of the main methods I have in it. I have one project with a main method for a server and a different one for the client and I want to produce a jar file which will run each of these accordingly

A different SO question lead me to this: http://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ Which works fine to create a single jar using one main method however when I create multiple artefacts each with the correct settings for each one and click apply, they all point to the same main class.

like image 706
RichyHBM Avatar asked Nov 11 '13 21:11

RichyHBM


People also ask

How do I select multiple JARs in IntelliJ?

Select the + icon and select 1 JARs or Directories option. select your JAR file or you can select the directories. Click on the OK button.


1 Answers

  1. Create two directories (some where in your source tree). One for each JAR to be built. For example: enter image description here
  2. Go to the "Artifacts" pane in "Project Structure"
  3. Create a new JAR artifact configuration
  4. Complete the fields in the "Create Jar from Modules" dialog. For the "Directory for META-INF/MANIFEST.MF field", change the default value to the path of the appropriate directory created in step 1. enter image description here
  5. Click OK
  6. In the right pane, rename the artifact definition to an appropriate name.
  7. Repeat steps 3-6 for the next JAR enter image description here

Idea will create the manifest files. For example:

enter image description here

However, when it builds the JARs, IDEA will copy the META-INF directory and its content to the root of the JAR so your MANIFEST.MF file will be in the correct location.

like image 136
Javaru Avatar answered Oct 13 '22 17:10

Javaru