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

标签 java spring jetty maven pom.xml

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

pom 中删除一些 jar 文件并将它们放入 WEB-INF/lib 文件夹后,它们不再可找到 -我收到许多 "Cannot find symbol" 构建错误。

我也尝试将 jar 放在 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.

最佳答案

As I mentioned in a comment below, I want to remove them from the pom because even though they are in my local Maven repository, while maven is building the project it always says it is trying to download each of these local dependencies, adding extra time onto each build cycle.

您没有显示任何说明确切问题的痕迹(这通常会有所帮助),但除非您的本地依赖项是 SNAPSHOT 依赖项(这对于手动安装的 Artifact 来说是一个糟糕的选择),我不认为您对行为是准确的。

I was hoping to copy these jars to a location where they will be found by the build process but without Maven trying to download any resources each time.

我的猜测是依赖项只是缺少一个 .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] 

Regardless of how horrible it may seem, I find Maven's behavior here more horrible.

Using system scope dependencies doesn't seem horrible, it is an horrible and discouraged practice and should be avoided in 99,999% of the cases. Quoting the provided link:

system: This dependency is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessary in certain edge cases. The system scope includes the <systemPath> element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path: ${JAVA_HOME} for instance.

Just use Maven the right way and you won't have problems. With system scoped dependencies (why on earth people keep suggesting to abuse them?!), I predict more troubles later.


As you correctly guessed, the htmlunit that is in my local maven repository does not have pom files. I also can't remember how I installed it.

So I'm not crazy :) Obviously, my suggestion is to fix the problem and to provide the missing .pom files. If you don't want to reinstall the artifacts (so that Maven could generate them), you can create the .pom manually. A simple file like this would suffice:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>ze.groupId</groupId>
  <artifactId>some-artifact-id</artifactId>
  <version>X.Y.Z</version>
</project>

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

You may be asking why I am using version 2.8 - well, it contains some patches that are essential for my project.

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

(...) I get an error during the build that says "command line too long":

很遗憾,您应该向 datanucleus 报告此问题。

关于java - 在 `WEB-INF/lib` 文件夹和 `src/main/resources` 文件夹中找不到 jar 文件的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025629/

相关文章:

java - spring 中的 validator 应该访问数据库吗?

java - 如何将 FirebaseApp.initializeApp 用于 FirebaseRemoteConfig

java - Java通用Map的序列化和反序列化及外部使用

java - 使用 IDE 运行 Spring-boot 的 main

java - 如何将消费者异常作为确认来处理?

javascript - 如何让 maven jetty 插件知道额外的 web 目录?

java - 如何允许用户选择并上传特定文件夹中的多个文件并在java中获取该文件夹的路径

java - 警告 : org. springframework.web.servlet.PageNotFound - 在名称为 'appServlet' 的 DispatcherServlet 中未找到带有 URI [/board/] 的 HTTP 请求的映射

java - DWR - Jetty 9 中的 splinter 反射异常

java - java中等待异步http请求