简体   繁体   English

Maven pom.xml更改清单主类

[英]Maven pom.xml change manifest mainclass

I'm working on a project where I have gotten a sample code that is build with Maven. 我正在一个项目中,我已经获得了用Maven构建的示例代码。 In the pom.xml there is 在pom.xml中有

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.xxx.research.control.ControlClass</mainClass>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
            </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>

Now I have written my own code and I am trying to reuse this pom since I'm new to maven. 现在,我已经编写了自己的代码,并且由于我是Maven新手,所以我尝试重用此pom。 I have tried to change <mainClass>com.xxx.research.control.Main</mainClass> to <mainClass>project.Main</mainClass> because thats where my code is. 我试图将<mainClass>com.xxx.research.control.Main</mainClass>更改为<mainClass>project.Main</mainClass>因为那是我的代码所在的位置。 In Eclipse I have it in the sam source folder but in a package "project". 在Eclipse中,它位于sam源文件夹中,但位于“项目”包中。

When I do maven clean install with the original pom I can run the jar that it produces just fine but when I modify it to build my code I get Exception in thread "main" java.lang.NoClassDefFoundError: project/Main . 当我使用原始pom进行maven全新安装时,我可以运行它生成的jar,但是当我对其进行修改以构建代码时,我Exception in thread "main" java.lang.NoClassDefFoundError: project/Main得到Exception in thread "main" java.lang.NoClassDefFoundError: project/Main

What am I missing here? 我在这里想念什么?

Thanks in advance. 提前致谢。

By default maven looks under src/main/java folder for your source code, so you have to put your main class on src/main/java/project/Main.java 默认情况下,maven在src / main / java文件夹下查找源代码,因此您必须将主类放在src / main / java / project / Main.java上

Have a read at the maven manual, it also has some folder structure for resources and unit tests that will be included into classpath: 阅读maven手册,它也具有一些资源和单元测试的文件夹结构,这些结构将包含在classpath中:

  • src/main/resources src / main / resources
  • src/test/java src /测试/ java
  • src/test/resources src / test / resources

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM