如果我有一个带有maven文件夹的项目,其中一个包含应该启动的主类(并且可以从那里启动),当我从头文件夹中选择Run as
- Java Application
时,我应该如何让Eclipse和Maven启动该类?
编辑:
maven-exec-plugin没有帮助:
<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>
不显示任何错误,但head项目无法启动use_annotations.UseAnnotationsLaunch.main。我得到“选择不包含主要类型”
请注意,Maven编译命令正确调用maven模块的编译。这是eclipse和maven模块的问题。
如果我没记错的话,Eclipse和Maven正在使用他们自己的类路径/运行配置,所以你可以使用Eclipse的运行配置,或者你可以在你的pom.xml中设置maven-exec-plugin并设置你的运行配置来调用maven。
如果使用Eclipse的内置“运行”正确设置了类路径可能会更舒服,但是如果您想在其他计算机上编译并运行它,则使用Maven运行配置将确保您的项目设置正确。
这是我的旧项目的设置,有exec插件和jar-with-dependencies(可执行jar)。请不要介意插件版本......
<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>