简体   繁体   中英

Maven pom.xml change manifest mainclass

I'm working on a project where I have gotten a sample code that is build with Maven. In the pom.xml there is

<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. I have tried to change <mainClass>com.xxx.research.control.Main</mainClass> to <mainClass>project.Main</mainClass> because thats where my code is. In Eclipse I have it in the sam source folder but in a package "project".

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 .

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

Have a read at the maven manual, it also has some folder structure for resources and unit tests that will be included into classpath:

  • src/main/resources
  • src/test/java
  • src/test/resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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