1

If I have a project with maven folders, one of them contains the main class that should be launched (and can be launched from there), how should I make Eclipse and Maven to launch that class when I choose Run as - Java Application from the head folder?

Edit:

The maven-exec-plugin does not help:

              <plugin>  
                   <groupId>org.codehaus.mojo</groupId>  
                   <artifactId>exec-maven-plugin</artifactId>  
                   <version>1.1.1</version>  
                   <executions>  
                    <execution>  
                     <goals>  
                      <goal>java</goal>  
                     </goals>  
                     <configuration>  
                      <mainClass>use_annotations.UseAnnotationsLaunch</mainClass>  
                     </configuration>  
                    </execution>  
                   </executions>                  </plugin> 

Does not show any errors, but the head project cannot launch use_annotations.UseAnnotationsLaunch.main. I am getting "Selection does not contain a main type"

Notice, that Maven compile command calls compile for maven modules correctly. It is the problem of eclipse and maven modules.

Gangnus
  • 24,044
  • 16
  • 90
  • 149

1 Answers1

0

Eclipse and Maven are using their own classpath/run configuration if I recall correctly, so you can use Eclipse's run config or you can setup maven-exec-plugin in your pom.xml and set up your run configuration to call maven.

If your classpath is set correctly using Eclipse's built-in 'Run' may be more comfortable, but using Maven run configuration will ensure your project is set up correctly if you wanted to compile and run it on other machine.

Here's a setup from my old project, there are both exec plugin and jar-with-dependencies (executable jar). Please don't mind plugin versions...

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1.1</version>
            <executions>
                <execution>
                    <phase>deploy</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>my.old.project.package.gui.MainWindow</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.old.project.package.gui.MainWindow</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Vic
  • 308
  • 2
  • 7
  • Tried - with no results. Head project sees module, but does not launch it. – Gangnus Apr 24 '19 at 09:25
  • It looks like you passed "main" method to configuration instead of class name. Not sure if 'test' phase is a proper place for application exeuction, too, but it shouldn't be too much of an issue. – Vic Apr 24 '19 at 11:14
  • Thank you. But the proposed changes changed nothing.The same with the second plugin – Gangnus Apr 24 '19 at 11:40
  • Try running it through command line maven call? If it works, it's just Eclipse issue, if it doesn't, well, there must be something wrong with your pom.xml, too. Have you tried solutions from similar threads, like this? https://stackoverflow.com/questions/16225177/error-selection-does-not-contain-a-main-type – Vic Apr 24 '19 at 13:03
  • Maven compile command calls compile for maven modules correctly. Yes, it IS eclipse issue, eclipse simply does not create the jar of the module to be launched.But I have given eclipse in tags. – Gangnus Apr 24 '19 at 13:21