Eclipse部署多模塊項目到tomcat,啟動時找不到jar的解決方法。 ...
一、背景
最近在寫一個MQ框架-gmq,先寫的服務端,然後寫客戶端。感覺服務端和客戶端分成兩個獨立的項目不合適,於是改成了maven父子模塊的形式。父項目相當於一個殼,裡面包含服務端、客戶端兩個模塊。
二、問題描述
1、當時服務端是單獨一個項目的時候,啟動是正常的。pom配置如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.shuimutong</groupId> <artifactId>gmq-server</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>gmq</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <gmvc.version>1.0.1-SNAPSHOT</gmvc.version> <gdao.version>2.0.0-SNAPSHOT</gdao.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>me.lovegao</groupId> <artifactId>gdao</artifactId> <version>${gdao.version}</version> </dependency> <dependency> <groupId>com.shuimutong</groupId> <artifactId>gmvc</artifactId> <version>${gmvc.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.60</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.2</version> </dependency> </dependencies> <build> <finalName>com.shuimutong.gmq_server</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> </configuration> </plugin> </plugins> </build>View Code
2、然後改成了父子模塊的形式。
其中,父項目pom如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.shuimutong</groupId> <artifactId>gmq</artifactId> <version>${global.version}</version> <packaging>pom</packaging> <url>http://maven.apache.org</url> <modules> <module>gmq-server</module> <module>gmq-client</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <global.version>0.0.1-SNAPSHOT</global.version> <fastjson.version>1.2.60</fastjson.version> <gdao.version>2.0.0-SNAPSHOT</gdao.version> <gmvc.version>1.0.1-SNAPSHOT</gmvc.version> <gutil.version>0.0.2-SNAPSHOT</gutil.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>me.lovegao</groupId> <artifactId>gdao</artifactId> <version>${gdao.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.shuimutong</groupId> <artifactId>gmvc</artifactId> <version>${gmvc.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.shuimutong</groupId> <artifactId>gutil</artifactId> <version>${gutil.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.2</version> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> </configuration> </plugin> </plugins> </build> </project>View Code
GMQ服務端pom如下:
<?xml version="1.0"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.shuimutong</groupId> <artifactId>gmq</artifactId> <version>${global.version}</version> </parent> <groupId>com.shuimutong</groupId> <artifactId>gmq-server</artifactId> <packaging>war</packaging> <version>${global.version}</version> <name>gmq-server</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>me.lovegao</groupId> <artifactId>gdao</artifactId> </dependency> <dependency> <groupId>com.shuimutong</groupId> <artifactId>gmvc</artifactId> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> </dependencies> <build> <finalName>com.shuimutong.gmq_server</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <target>1.8</target> <source>1.8</source> </configuration> </plugin> </plugins> </build> </project>View Code
3、通過Eclipse部署到Tomcat啟動,具體日誌如下:
十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server.伺服器版本: Apache Tomcat/9.0.14 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server.構建: Dec 6 2018 21:13:53 UTC 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version number: 9.0.14.0 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Windows 10 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS.版本: 10.0 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: 結.造: amd64 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java 環境變數: D:\develop\jdk1.8.0_144\jre 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM 版本: 1.8.0_144-b01 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM.供應商: Oracle Corporation 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: E:\develop\work_space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: D:\develop\apache-tomcat-9.0.14 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=E:\develop\work_space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=D:\develop\apache-tomcat-9.0.14 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dwtp.deploy=E:\develop\work_space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.endorsed.dirs=D:\develop\apache-tomcat-9.0.14\endorsed 十一月 10, 2019 10:43:30 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dfile.encoding=UTF-8 十一月 10, 2019 10:43:30 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: Loaded APR based Apache Tomcat Native library [1.2.19] using APR version [1.6.5]. 十一月 10, 2019 10:43:30 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 十一月 10, 2019 10:43:30 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 十一月 10, 2019 10:43:30 上午 org.apache.catalina.core.AprLifecycleListener initializeSSL 信息: OpenSSL successfully initialized [OpenSSL 1.1.1a 20 Nov 2018] 十一月 10, 2019 10:43:30 上午 org.apache.coyote.AbstractProtocol init 信息: 初始化協議處理器 ["http-nio-8080"] 十一月 10, 2019 10:43:31 上午 org.apache.coyote.AbstractProtocol init 信息: 初始化協議處理器 ["ajp-nio-8009"] 十一月 10, 2019 10:43:31 上午 org.apache.catalina.startup.Catalina load 信息: 伺服器在[813]毫秒內初始化 十一月 10, 2019 10:43:31 上午 org.apache.catalina.core.StandardService startInternal 信息: Starting service [Catalina] 十一月 10, 2019 10:43:31 上午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet engine: [Apache Tomcat/9.0.14] 十一月 10, 2019 10:43:32 上午 org.apache.jasper.servlet.TldScanner scanJars 信息: 至少有一個JAR被掃描用於TLD但尚未包含TLD。 為此記錄器啟用調試日誌記錄,以獲取已掃描但未在其中找到TLD的完整JAR列表。 在掃描期間跳過不需要的JAR可以縮短啟動時間和JSP編譯時間。 十一月 10, 2019 10:43:34 上午 org.apache.jasper.servlet.TldScanner scanJars 信息: 至少有一個JAR被掃描用於TLD但尚未包含TLD。 為此記錄器啟用調試日誌記錄,以獲取已掃描但未在其中找到TLD的完整JAR列表。 在掃描期間跳過不需要的JAR可以縮短啟動時間和JSP編譯時間。 十一月 10, 2019 10:43:34 上午 org.apache.catalina.core.ApplicationContext log 信息: Marking servlet [gmvc] as unavailable 十一月 10, 2019 10:43:34 上午 org.apache.catalina.core.StandardContext loadOnStartup 嚴重: Servlet [gmvc] in web application [/com.shuimutong.gmq_server] threw load() exception java.lang.ClassNotFoundException: com.shuimutong.gmvc.handler.XDispatcherServlet at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1343) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1173) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1031) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4849) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.startup.Catalina.start(Catalina.java:637) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492) 十一月 10, 2019 10:43:34 上午 org.apache.coyote.AbstractProtocol start 信息: 開始協議處理句柄["http-nio-8080"] 十一月 10, 2019 10:43:34 上午 org.apache.coyote.AbstractProtocol start 信息: 開始協議處理句柄["ajp-nio-8009"] 十一月 10, 2019 10:43:34 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in [3,492] milliseconds 十一月 10, 2019 10:43:37 上午 org.apache.catalina.core.StandardServer await 信息: A valid shutdown command was received via the shutdown port. Stopping the Server instance. 十一月 10, 2019 10:43:37 上午 org.apache.coyote.AbstractProtocol pause 信息: Pausing ProtocolHandler ["http-nio-8080"] 十一月 10, 2019 10:43:37 上午 org.apa