gpt4 book ai didi

java - 即使 jar 在 WEB-INF/lib 中,也找不到包

转载 作者:行者123 更新时间:2023-11-28 23:34:23 26 4
gpt4 key购买 nike

我有一个在 Netbeans 中启动的 Tomcat 8 Web 项目。在 Netbeans 中,我设置了一些全局库,然后将它们添加到项目中。在 Netbeans 中构建项目完美无缺。

问题是当我尝试使用 Ant 在 Unix 平台上构建时。我使用 Netbeans 自动生成的 build.xml 文件,唯一的区别是我现在必须指定这些“全局”库的位置,我这样做:

ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE" clean dist

然而,这会导致这些类型的错误:

error: package org.springframework.beans.factory does not exist

如果我查看 web/WEB-INF/lib 中的构建文件夹,jar 就在那里,如果我查看它,我确实找到了 org.springframework.beans.factory 类。

如果我在 Debug模式下运行 ant,它会清楚地指出正在复制库:

[copy] Copying /libs/spring-framework-4.0.6.RELEASE/spring-beans-4.0.6.RELEASE.jar to /App/build/web/WEB-INF/lib/spring-beans-4.0.6.RELEASE.jar

据我了解,WEB-INF/lib 目录默认位于类路径中。这不是会发生什么吗?我是否需要专门告诉它将该目录添加到类路径中?

最佳答案

自己找到了解决方案,结果我必须专门引用每个jar,引用目录是不够的。

所以这样:

ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE" clean dist

应该是这样的:

ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE/spring-aop-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-aspects-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-beans-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-context-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-context-support-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-core-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-expression-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-framework-bom-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-instrument-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-instrument-tomcat-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-jdbc-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-jms-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-messaging-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-orm-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-oxm-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-test-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-tx-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-web-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-webmvc-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-webmvc-portlet-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-websocket-4.0.6.RELEASE.jar"  clean dist

关于java - 即使 jar 在 WEB-INF/lib 中,也找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26018332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com