在`WEB-INF / lib`文件夹中找不到jar文件的解决方案,也没有在`src / main / resources`文件夹中找到?

我有一个在Jetty / App Engine / Spring上运行的Java应用程序。

pom删除一些jar文件并将它们放入WEB-INF/lib文件夹后,它们不再可见 – 我收到了大量的"Cannot find symbol"构建错误。

我也尝试将jar放在src/main/resources文件夹中 – 但结果相同。

如何在不引用它们的情况下使这些jar子找到它们?

PASCAL问题的最新消息:

以下是我收到的“无法查找资源”消息:

 Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/htmlunit/2.8/htmlunit-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit:pom:2.8' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn/re pository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/htmlunit/2.8/htmlunit-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit:pom:2.8' in repository jboss-repo (https://repository.jboss.org/nexus/content/groups /public) Downloading: http://repo1.maven.org/maven2/htmlunit/htmlunit/2.8/htmlunit-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit:pom:2.8' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/apache-mime/0.6/apache-mime-0.6.pom [INFO] Unable to find resource 'htmlunit:apache-mime:pom:0.6' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn /repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/apache-mime/0.6/apache-mime-0.6.pom [INFO] Unable to find resource 'htmlunit:apache-mime:pom:0.6' in repository jboss-repo (https://repository.jboss.org/nexus/content/gro ups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/apache-mime/0.6/apache-mime-0.6.pom [INFO] Unable to find resource 'htmlunit:apache-mime:pom:0.6' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/commons-codec/1.4/commons-codec-1.4.pom [INFO] Unable to find resource 'htmlunit:commons-codec:pom:1.4' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/s vn/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/commons-codec/1.4/commons-codec-1.4.pom [INFO] Unable to find resource 'htmlunit:commons-codec:pom:1.4' in repository jboss-repo (https://repository.jboss.org/nexus/content/g roups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/commons-codec/1.4/commons-codec-1.4.pom [INFO] Unable to find resource 'htmlunit:commons-codec:pom:1.4' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/commons-collections/3.2.1/commons-collections-3.2.1.pom [INFO] Unable to find resource 'htmlunit:commons-collections:pom:3.2.1' in repository maven-gae-repo (http://maven-gae-plugin.googleco de.com/svn/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/commons-collections/3.2.1/commons-collections-3.2.1.pom [INFO] Unable to find resource 'htmlunit:commons-collections:pom:3.2.1' in repository jboss-repo (https://repository.jboss.org/nexus/c ontent/groups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/commons-collections/3.2.1/commons-collections-3.2.1.pom [INFO] Unable to find resource 'htmlunit:commons-collections:pom:3.2.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/commons-logging/1.1.1/commons-logging-1.1.1.pom [INFO] Unable to find resource 'htmlunit:commons-logging:pom:1.1.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.c om/svn/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/commons-logging/1.1.1/commons-logging-1.1.1.pom [INFO] Unable to find resource 'htmlunit:commons-logging:pom:1.1.1' in repository jboss-repo (https://repository.jboss.org/nexus/conte nt/groups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/commons-logging/1.1.1/commons-logging-1.1.1.pom [INFO] Unable to find resource 'htmlunit:commons-logging:pom:1.1.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/cssparser/0.9.5/cssparser-0.9.5.pom [INFO] Unable to find resource 'htmlunit:cssparser:pom:0.9.5' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn /repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/cssparser/0.9.5/cssparser-0.9.5.pom [INFO] Unable to find resource 'htmlunit:cssparser:pom:0.9.5' in repository jboss-repo (https://repository.jboss.org/nexus/content/gro ups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/cssparser/0.9.5/cssparser-0.9.5.pom [INFO] Unable to find resource 'htmlunit:cssparser:pom:0.9.5' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/htmlunit-core-js/2.8/htmlunit-core-js-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit-core-js:pom:2.8' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.co m/svn/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/htmlunit-core-js/2.8/htmlunit-core-js-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit-core-js:pom:2.8' in repository jboss-repo (https://repository.jboss.org/nexus/conten t/groups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/htmlunit-core-js/2.8/htmlunit-core-js-2.8.pom [INFO] Unable to find resource 'htmlunit:htmlunit-core-js:pom:2.8' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/httpclient/4.0.1/httpclient-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpclient:pom:4.0.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/sv n/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/httpclient/4.0.1/httpclient-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpclient:pom:4.0.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/gr oups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/httpclient/4.0.1/httpclient-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpclient:pom:4.0.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/httpcore/4.0.1/httpcore-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpcore:pom:4.0.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn/ repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/httpcore/4.0.1/httpcore-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpcore:pom:4.0.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/grou ps/public) Downloading: http://repo1.maven.org/maven2/htmlunit/httpcore/4.0.1/httpcore-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpcore:pom:4.0.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/httpmime/4.0.1/httpmime-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpmime:pom:4.0.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn/ repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/httpmime/4.0.1/httpmime-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpmime:pom:4.0.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/grou ps/public) Downloading: http://repo1.maven.org/maven2/htmlunit/httpmime/4.0.1/httpmime-4.0.1.pom [INFO] Unable to find resource 'htmlunit:httpmime:pom:4.0.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/nekohtml/1.9.14/nekohtml-1.9.14.pom [INFO] Unable to find resource 'htmlunit:nekohtml:pom:1.9.14' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn /repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/nekohtml/1.9.14/nekohtml-1.9.14.pom [INFO] Unable to find resource 'htmlunit:nekohtml:pom:1.9.14' in repository jboss-repo (https://repository.jboss.org/nexus/content/gro ups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/nekohtml/1.9.14/nekohtml-1.9.14.pom [INFO] Unable to find resource 'htmlunit:nekohtml:pom:1.9.14' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/sac/1.3/sac-1.3.pom [INFO] Unable to find resource 'htmlunit:sac:pom:1.3' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn/reposit ory) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/sac/1.3/sac-1.3.pom [INFO] Unable to find resource 'htmlunit:sac:pom:1.3' in repository jboss-repo (https://repository.jboss.org/nexus/content/groups/publ ic) Downloading: http://repo1.maven.org/maven2/htmlunit/sac/1.3/sac-1.3.pom [INFO] Unable to find resource 'htmlunit:sac:pom:1.3' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/serializer/2.7.1/serializer-2.7.1.pom [INFO] Unable to find resource 'htmlunit:serializer:pom:2.7.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/sv n/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/serializer/2.7.1/serializer-2.7.1.pom [INFO] Unable to find resource 'htmlunit:serializer:pom:2.7.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/gr oups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/serializer/2.7.1/serializer-2.7.1.pom [INFO] Unable to find resource 'htmlunit:serializer:pom:2.7.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/xalan/2.7.1/xalan-2.7.1.pom [INFO] Unable to find resource 'htmlunit:xalan:pom:2.7.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn/rep ository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/xalan/2.7.1/xalan-2.7.1.pom [INFO] Unable to find resource 'htmlunit:xalan:pom:2.7.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/groups/ public) Downloading: http://repo1.maven.org/maven2/htmlunit/xalan/2.7.1/xalan-2.7.1.pom [INFO] Unable to find resource 'htmlunit:xalan:pom:2.7.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/xercesImpl/2.9.1/xercesImpl-2.9.1.pom [INFO] Unable to find resource 'htmlunit:xercesImpl:pom:2.9.1' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/sv n/repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/xercesImpl/2.9.1/xercesImpl-2.9.1.pom [INFO] Unable to find resource 'htmlunit:xercesImpl:pom:2.9.1' in repository jboss-repo (https://repository.jboss.org/nexus/content/gr oups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/xercesImpl/2.9.1/xercesImpl-2.9.1.pom [INFO] Unable to find resource 'htmlunit:xercesImpl:pom:2.9.1' in repository central (http://repo1.maven.org/maven2) Downloading: http://maven-gae-plugin.googlecode.com/svn/repository/htmlunit/xml-apis/1.3.04/xml-apis-1.3.04.pom [INFO] Unable to find resource 'htmlunit:xml-apis:pom:1.3.04' in repository maven-gae-repo (http://maven-gae-plugin.googlecode.com/svn /repository) Downloading: https://repository.jboss.org/nexus/content/groups/public/htmlunit/xml-apis/1.3.04/xml-apis-1.3.04.pom [INFO] Unable to find resource 'htmlunit:xml-apis:pom:1.3.04' in repository jboss-repo (https://repository.jboss.org/nexus/content/gro ups/public) Downloading: http://repo1.maven.org/maven2/htmlunit/xml-apis/1.3.04/xml-apis-1.3.04.pom [INFO] Unable to find resource 'htmlunit:xml-apis:pom:1.3.04' in repository central (http://repo1.maven.org/maven2) 

它们都与htmlunit版本2.8相关,而不是我之前说过导致错误的gdata库。

这些是我正在尝试构建的项目的pom文件中的相应htmlunit条目:

   htmlunit htmlunit 2.8   htmlunit apache-mime 0.6   htmlunit commons-codec 1.4   htmlunit commons-collections 3.2.1   htmlunit commons-logging 1.1.1   htmlunit cssparser 0.9.5   htmlunit htmlunit-core-js 2.8   htmlunit httpclient 4.0.1   htmlunit httpcore 4.0.1   htmlunit httpmime 4.0.1   htmlunit nekohtml 1.9.14   htmlunit sac 1.3   htmlunit serializer 2.7.1   htmlunit xalan 2.7.1   htmlunit xercesImpl 2.9.1   htmlunit xml-apis 1.3.04  

正如您所猜测的那样,我本地maven存储库中的htmlunit没有pom文件。 我也记不起我是如何安装它的。 在包含jar文件的每个子目录中,没有pom文件 – 而是一个名为htmlunit-2.8.pom.lastUpdated的文件,其中包含以下文本:

 #Last modified on: Tue Oct 26 13:43:29 BST 2010 #Tue Oct 26 13:43:29 BST 2010 http\://maven-gae-plugin.googlecode.com/svn/repository=1288097006231 https\://repository.jboss.org/nexus/content/groups/public=1288097009578 http\://repo1.maven.org/maven2=1288097009912 

您可能会问我为什么使用2.8版本 – 它包含一些对我的项目至关重要的补丁。 版本2.7从maven依赖构建良好:

  net.sourceforge.htmlunit htmlunit 2.7  

但是当我使用它时:

  net.sourceforge.htmlunit htmlunit 2.8  

在构建期间出现“命令行太长”时出错:

 10/26/10 9:03:27 PM BST: [ERROR] Standard error from the DataNucleus tool + org.datanucleus.enhancer.DataNucleusEnhancer : 10/26/10 9:03:27 PM BST: [ERROR] -------------------- 10/26/10 9:03:27 PM BST: [ERROR] The command line is too long. 

正如我在下面的评论中提到的,我想将它们从pom中移除,因为即使它们在我的本地Maven存储库中,而maven正在构建项目,它总是说它正在尝试下载这些本地依赖项中的每一个,增加额外的时间到每个构建周期。

您没有显示任何描述确切问题的跟踪(这通常有帮助),但除非您的本地依赖项是SNAPSHOT依赖项(并且这对于手动安装的工件来说是一个糟糕的选择),我不认为您对该行为的描述是准确的。

我希望将这些jar子复制到可以通过构建过程找到它们的位置,但是没有Maven每次都尝试下载任何资源。

我的猜测是,依赖项只是缺少.pom文件,这是Maven试图下载的内容。 使用以下命令在本地存储库中安装JAR时,可以告诉Maven为您生成此pom:

 mvn install:install-file -Dfile = your-artifact-1.0.jar \
                          [-DgroupId = org.some.group] \
                          [-DartifactId =你的神器]
                          [-Dversion = 1.0] \
                          [-Dpackaging = jar] \
                          [-DgeneratePom =真] 

无论看起来多么可怕,我发现Maven在这里的行为更加可怕。

使用system范围依赖性似乎并不可怕, 这是一种可怕的, 令人沮丧的做法 ,应该在99,999%的案例中避免使用。 引用提供的链接:

system:在项目生命周期的某个阶段需要此依赖项,但这是系统特定的。 不鼓励使用此范围:这被认为是一种“高级”function,只有在您真正理解其使用的所有后果时才能使用,如果实际上无法量化则可能非常困难。 根据定义,此范围使您的构建不可移植。 在某些边缘情况下可能是必要的。 系统范围包括元素,该元素指向此依赖项在本地计算机上的物理位置。 因此,它用于指代预期存在于给定本地机器上而不是存储库中的某个工件; 并且其路径可能因机器而异。 systemPath元素可以在其路径中引用环境变量:例如${JAVA_HOME}

只要以正确的方式使用Maven,就不会有问题。 有了system范围的依赖关系(为什么人们一直建议滥用它们?!),我预测会有更多的麻烦。


正如您所猜测的那样,我本地maven存储库中的htmlunit没有pom文件。 我也记不起我是如何安装它的。

所以我不是疯了:)显然,我的建议是解决问题并提供丢失的.pom文件。 如果您不想重新安装工件(以便Maven可以生成它们),您可以手动创建.pom 。 像这样的简单文件就足够了:

  4.0.0 ze.groupId some-artifact-id XYZ  

但请不要切换到system范围的依赖关系,从长远来看,这将弊大于利。

您可能会问我为什么使用2.8版本 – 它包含一些对我的项目至关重要的补丁。

你当然有充分的理由,我甚至不会讨论它们。

(…)我在构建过程中遇到“命令行太长”的错误:

这很不幸,你应该把这个问题报告给datanucleus。

  org.companyname artifact versionNumber system PATH_TO_YOUR_JAR  

尝试这样的事情

范围系统的依赖关系始终可用,并且不会在存储库中查找。 它们通常用于告诉Maven有关JDK或VM提供的依赖关系。 因此,系统依赖性对于解决现在由JDK提供的工件的依赖性特别有用,但是可以在之前单独下载。 典型示例是JDBC标准扩展或Java身份validation和授权服务(JAAS)。

一个简单的例子是:

  ...   javax.sql jdbc-stdext 2.0 system ${java.home}/lib/rt.jar   ...  
  • 资源