run jar

In Intellij11, how can I create a run configuration that runs a jar artifact?  (I would prefer not to set the jar to be in the classpath, but I can if I knew how.)

5 comments
Comment actions Permalink

Hi Jayen,

You can configure that jar as a library dependency and specify target main class name at run configuration.

Denis

0
Comment actions Permalink

How will intellij know to use the main class from the jar file, instead of the main class from the module's compile output?  Or will I have to make an source-less module for each jar I wish to run?

0
Comment actions Permalink
  1. The ide doesn't have support for executing java programs similar to 'java -jar youjar.jar';
  2. You can add target jar as a library dependency (that makes it be at the classpath) and manually specify main class to use at ide run configuration;
  3. I'm afraid I don't understand that sourceless modules idea;

Denis

0
Comment actions Permalink

I have a run configuration which currently runs a main class in a module.  I also have a jar artifact created from that module.  I want to test that everything is packaged into the artifact properly by running the main class from the jar instead of from the module's compiled output.

If I add the jar artifact to the module, then which main class will run (as both will be in the class path)?

I can create another module with no sources, add the jar artifact as a dependency, and specify the same main class in a run configuration, allowing me to have two run configurations which run the same main class, but one from the jar, and one from outside the jar.

0
Comment actions Permalink

I want to test that everything is packaged into the artifact properly by running the main class from the jar instead of from the module's compiled output.


The only way is to run 'java -jar yourjar.jar' from command line then.

Denis
0

Please sign in to leave a comment.