0

I am running a Maven project from eclipse and want to setup a Run Configuration with Goals compile exec:java, which needs a exec.mainClass parameter. Because I have different main classes in my project, I would like class and package name the currently selected resource to be used when running. What are the correct Run Variable to insert as a value for the parameter?

Thomas
  • 10,289
  • 13
  • 39
  • 55

1 Answers1

1

I use the following configuration to quickly run the main method of the currently selected class. I know you just asked for the parameters but it I'll provide more detailed steps for other visitors since I didn't found any solution on the net.

Prerequisite: m2e eclipse plugin, exec-maven-plugin

  1. Select Run as > Maven build …
  2. Use the goal exec:java
  3. optional: provide a profile name
  4. optional: Select Debug Output
  5. Click Add … to create a parameter
    • Name: exec.mainClass
    • Value: ${java_type_name} (this provides the currently selected resource's full java name)

Now whenever you use this run configuration it will take the current class as parameter and execute its main method. The ${java_type_name} variable is provided by eclipse, so it should also work somehow without using m2e.

One thing to mention is that the exec.mainClass parameter didn't work for me when I provided a goal and default configuration in the pom.xml. Not sure if it's a bug, I did something wrong, or simply not possible. I had to remove any goals and just include the plugin without configuring it in the build to make it work:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
</plugin>
kapex
  • 28,903
  • 6
  • 107
  • 121