Your Location is: Home > Eclipse

The problem of ClassNotFoundException when introduced another maven project in the same workspace into the deployment assembly

From: Zaire View: 3340 Universe Whole-Xuan 

Question

https://segmentfault.com/img/bVbHSUW

enter image description here

As shown in the figure, introduce another Maven project selenium geetest crack (hereinafter referred to as project B) in the deployment assembly of the Maven project regking (hereinafter referred to as project a). When the reflect class in project B from project A, the following error will be reported

java.lang.ClassNotFoundException: com.github.wycm.API._douban
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
at model.API.base.APIBase.executeSeleniumByReflectUtil2(APIBase.java:2394)
at model.API.base.APIBase.doRequest(APIBase.java:1481)
at model.API.base.APIBase.lambda$0(APIBase.java:1558)
at com.github.johnsonmoon.util.Retry.lambda$0(Retry.java:197)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)

And sometimes an error is reported when running project a java.lang.ClassNotFoundException Dependency introduced in project B not found

However, if you export project B as a jar file and import it into the deployment assembly of project a,seem the these error will not be report

My question is how to modify project B's pom.xml fix this error by using maven-assembly-plugin or other configurations?below is project A's configuration, but not work

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.2</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <!-- <classesDirectory>${project.basedir}/src/main/webapp/WEB-INF/classes</classesDirectory> -->
                    <outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>false</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
            </execution>
        </executions>
    </plugin>

Because I want directly introduce the projects in the same workspace into the deployment assembly, that is, instantaneous change and use instead of exporting jar files and importing them.

Best answer