且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-08-22 18:16:10


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

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依赖项(并且对于手动安装的工件,这将是一个糟糕的选择),我不认为你对行为的描述是准确的。

You aren't showing any trace illustrating the exact problem (this usually helps) but unless your local dependencies are SNAPSHOT dependencies (and that would be a bad choice for manually installed artifacts), I don't think your description of the behavior is accurate.


我希望将这些罐子复制到构建过程中找到它们的位置,但没有Maven尝试下载任何资源时间。

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:

My guess is that the dependencies are just missing a .pom file, which is what Maven is trying to download. You can tell Maven to generate this pom for you when installing a JAR in your local repository using:


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在这里的行为更加可怕。

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

使用系统范围依赖关系似乎可怕,这是一个可怕的气馁实践,99,999%的案例应避免使用。引用提供的链接:

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

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.

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

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.


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

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.

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

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>

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

But please, don't switch to system scoped dependencies, this will do more harm than good on the long run.


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

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

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

You certainly have good reasons and I won't even discuss them.


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

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

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

That's unfortunate, and you should report this problem to datanucleus.