NutzCN Logo
问答 tomcat生产,maven引用本地jar找不到
发布于 113天前 作者 qq_8c799e25 128 次浏览 复制 上一个帖子 下一个帖子
标签:

我的工程有两个jar包是本地的, 采用eclipse的run on server正常启动(我把这两个jar加到 run Configuration 的Apache Tomcat v8.5 32 at localhost的classpath中),
但是采用war包发布正式环境后就提示找不到类

我的pom.xml

<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<warSourceDirectory>WebContent</warSourceDirectory>
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<webResources>
                    <resource>
                        <directory>${project.basedir}/libs</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                    </resource>
                </webResources>
				</configuration>
			</plugin>

.....
		<dependency>
			<groupId>com.tencent.lib</groupId>
			<artifactId>TencentFetchLib</artifactId>
			<version>1.0.0</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/libs/fetchlib/TencentFetchLib.jar</systemPath>
		</dependency>
		<dependency>
			<groupId>com.android.dzh</groupId>
			<artifactId>dzhcore</artifactId>
			<version>5.8.5</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/libs/dzh/dazhihui_5_85_dex2jar-m.jar</systemPath>
		</dependency>

生成的war包,在WEB-INF\lib下确实有那两个jar包所在的目录dzh和fetchlib,里面jar都在,但是引用不到他们。

我强行将dzh和fetchlib目录下的jar复制到WEB-INF\lib下来,但是启动tomcat不了,报错:

02-May-2017 15:07:44.215 严重 [main] org.apache.catalina.startup.Catalina.start The required Server component failed to start so Tomcat is unable to start.
 org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:656)
	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:355)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 11 more

我发现这篇比较类似:https://nutz.cn/yvr/t/7p0a5gtjtkgtsq38s6pe6b11ja
但是我这打包没有问题,参考价值不大

在tomcat里,正确的引入maven本地jar的姿势是怎样的?
先谢谢啦!

6 回复
		<dependency>
			<groupId>org.abc</groupId>
			<artifactId>def</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>${project.basedir}}/libs/xxx.jar</systemPath>
		</dependency>

安装到构建机器的repository里面去吧。
参考一下:http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

@wendal 按你说的那样设置可以,但是发现很奇怪的一个现象:我打的war里面,这两个jar都被修改了,md5变了,而且大小也变了。所以tomcat解压失败。

我临时把原文件替换,发现可以启动!

多次试了几遍,打出来的war包这两个文件总是被破坏,其它jar是好的(我用winrar打开来测试,如果破坏了会报错)

resource去掉

你是说把war包的resource去掉?

<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<warSourceDirectory>WebContent</warSourceDirectory>
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<webResources>
						<resource>
							<directory>${project.basedir}/libs</directory>
							<targetPath>WEB-INF/lib</targetPath>
							<filtering>true</filtering>
							<includes>
								<include>**/*.jar</include>
							</includes>
						</resource>
					</webResources>
				</configuration>
			</plugin>

那这两个jar包就不能输出到lib下了啊

scope=system 不会拷贝吗? 那就安装到本地maven库呗

添加回复
请先登陆
回到顶部