我有一个在Jetty / App Engine / Spring上运行的Java应用程序。
从jar
中删除一些pom
文件并将其放入WEB-INF/lib
文件夹后,它们将无法再找到 - 我收到了大量"Cannot find symbol"
版本错误。
我也尝试将jars放在src/main/resources
文件夹中 - 但结果相同。
如何在 pom
中引用这些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条目:
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>apache-mime</artifactId>
<version>0.6</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>cssparser</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit-core-js</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>httpcore</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>httpmime</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.14</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>sac</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>serializer</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
</dependency>
正如您所猜测的那样,我本地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依赖构建良好:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.7</version>
</dependency>
但是当我使用它时:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.8</version>
</dependency>
我在构建期间收到“命令行太长”的错误:
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.
答案 0 :(得分:3)
正如我在下面的评论中提到的,我想将它们从pom中删除,因为即使它们在我的本地Maven存储库中,而maven正在构建项目,它总是说它正在尝试下载这些本地依赖项,在每个构建周期中添加额外的时间。
您没有显示任何描述确切问题的跟踪(这通常会有所帮助),但除非您的本地依赖项是SNAPSHOT依赖项(对于手动安装的工件而言,这将是一个糟糕的选择),我不认为您的描述行为准确。
我希望将这些罐子复制到一个可以通过构建过程找到它们的位置,但是没有Maven每次都尝试下载任何资源。
我的猜测是,依赖项只缺少.pom
文件,这是Maven试图下载的内容。使用以下命令在本地存储库中安装JAR时,可以告诉Maven为您生成此pom:
mvn install:install-file -Dfile=your-artifact-1.0.jar \ [-DgroupId=org.some.group] \ [-DartifactId=your-artifact] \ [-Dversion=1.0] \ [-Dpackaging=jar] \ [-DgeneratePom=true]
无论看起来多么可怕,我发现Maven在这里的行为更加可怕。
使用system
范围依赖关系似乎可怕,这是一个可怕的discouraged练习,应该避免99,999%案件。引用提供的链接:
system:在项目生命周期的某个阶段需要此依赖项,但这是系统特定的。 不鼓励使用此范围:这被认为是一种“高级”功能,只有在您真正了解其使用的所有后果时才能使用,如果实际上无法量化则可能非常困难。根据定义,此范围使您的构建不可移植。在某些边缘情况下可能是必要的。系统范围包括
<systemPath>
元素,该元素指向此依赖关系在本地计算机上的物理位置。因此,它用于指代预期存在于给定本地机器上而不是存储库中的某个工件;并且其路径可能因机器而异。systemPath
元素可以在其路径中引用环境变量:例如${JAVA_HOME}
。
只要以正确的方式使用Maven,你就不会有问题。有system
范围的依赖关系(为什么人们一直建议滥用它们?!),我预测会有更多的麻烦。
正如您所猜测的那样,我本地maven存储库中的htmlunit没有pom文件。我也记不起我是如何安装它的。
所以我并不疯狂:)显然,我的建议是解决问题并提供缺少的.pom
文件。如果您不想重新安装工件(以便Maven可以生成它们),您可以手动创建.pom
。像这样的简单文件就足够了:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>ze.groupId</groupId>
<artifactId>some-artifact-id</artifactId>
<version>X.Y.Z</version>
</project>
但是请不要切换到system
范围的依赖关系,从长远来看,这将弊大于利。
你可能会问为什么我使用的是2.8版 - 好吧,它包含了一些对我的项目至关重要的补丁。
你当然有充分的理由,我甚至不会讨论它们。
(...)我在构建过程中遇到“命令行太长”的错误:
这很不幸,你应该把这个问题报告给datanucleus。
答案 1 :(得分:1)
<dependency>
<groupId>org.companyname</groupId>
<artifactId>artifact</artifactId>
<version>versionNumber</version>
<scope>system</scope>
<systemPath>PATH_TO_YOUR_JAR</systemPath>
</dependency>
尝试这样的事情
范围系统的依赖关系始终可用,并且不会在存储库中查找。它们通常用于告诉Maven有关JDK或VM提供的依赖关系。因此,系统依赖性对于解决现在由JDK提供的工件的依赖性特别有用,但是可以在之前单独下载。典型示例是JDBC标准扩展或Java身份验证和授权服务(JAAS)。
一个简单的例子是:
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>