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?
I am running a Maven project from eclipse and want to setup a Run
Share
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
exec:javaexec.mainClass${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.mainClassparameter 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: