Java 依赖项不应指向项目目录中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32384798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:26:24  来源:igfitidea点击:

dependencies should not point at files within the project directory

javamaven

提问by illuminati

I looked up the issue before hand and seen others with similar problems but none of the solutions worked for me.

我事先查了这个问题,看到其他人有类似的问题,但没有一个解决方案对我有用。

I am a complete noob with Maven but I just imported a project from GitHub. Now I am having problems with getting the dependencies to work. When I clean it gives me the following errors.

我是 Maven 的完全菜鸟,但我刚刚从 GitHub 导入了一个项目。现在我在让依赖项工作时遇到问题。当我清理它时,它给了我以下错误。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further         details.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-api:jar:API
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:bukkit:jar should not point at files within the project directory, ${project.basedir}/lib/bukkit-1.8.6-R0.1-SNAPSHOT.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-v1_7_R3:jar:v1_7_R3
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:craftbukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.7.9-R0.2-SNAPSHOT.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-v1_7_R4:jar:v1_7_R4
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:craftbukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.7.10-R0.1.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-v1_8_R1:jar:v1_8_R1
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:craftbukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.8.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-v1_8_R2:jar:v1_8_R2
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:craftbukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.8.3.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:skywarsreloadedplugin-v1_8_R3:jar:v1_8_R3
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:craftbukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.8.4.jar will be unresolvable by dependent projects @ line 19, column 19
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.walrusone.skywars:SkyWarsReloadedPlugin:jar:V2.8
[WARNING] 'dependencies.dependency.systemPath' for org.bukkit:bukkit:jar should not point at files within the project directory, ${project.basedir}/lib/craftbukkit-1.8.4.jar will be unresolvable by dependent projects @ line 72, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 

I believe this is different from the original error which was telling me it could not find it, so I went ahead and downloaded all .jar files and put it in the correct places. Now I have no clue what to do.

我相信这与告诉我找不到它的原始错误不同,所以我继续下载所有 .jar 文件并将其放在正确的位置。现在我不知道该怎么办。

The other problem I have is whenever I try to edit or add a class it doesn't act like a regular jar file. I cant do like Main.instance.stacticMethod() when I type Main. it just sits there.

我遇到的另一个问题是,每当我尝试编辑或添加一个类时,它的行为都不像常规的 jar 文件。当我输入 Main 时,我不能像 Main.instance.stacticMethod() 那样做。它只是坐在那里。

If you need any additional files, please let me know.

如果您需要任何其他文件,请告诉我。

Also if anyone knows any good tutorial videos on maven

另外,如果有人知道关于 Maven 的任何好的教程视频

回答by hfhc2

The point of maven is that you shouldnot have to download the dependencies. Just clone the project. You should see a file pom.xmlin the root directory. Then enter

行家的一点是,你应该没有下载的依赖关系。只需克隆项目。您应该会pom.xml在根目录中看到一个文件。然后输入

mvn compile

This should compile the software and download the dependencies in the progress. The dependencies are not stored in the project folder, they are put in ~/.m2/...using the default config.

这应该编译软件并下载正在进行的依赖项。依赖项不存储在项目文件夹中,它们~/.m2/...使用默认配置放入。

Edit: The warnings seem to be a problem caused by the maintainers of the project not understanding maven correctly. They seem to have added jars to the project instead of dependencies.

编辑:警告似乎是由项目的维护者没有正确理解 maven 引起的问题。他们似乎在项目中添加了 jars 而不是依赖项。

Next edit: Consider for example the file pom.xmlin the v1_8_R3module: it links to jars in the base directory:

下一个编辑:pom.xmlv1_8_R3模块中的文件为例:它链接到基本目录中的 jars:

<dependency>
  <groupId>org.bukkit</groupId>
  <artifactId>craftbukkit</artifactId>
  <version>1.8.4-R0.1-SNAPSHOT</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/lib/craftbukkit-1.8.4.jar</systemPath>
  <type>jar</type>
  <optional>true</optional>
</dependency>

using system paths is generally discouraged. The correctway would have been for the devs to ship the jar as a separate artifact. See this question and the related answers

通常不鼓励使用系统路径。在正确的方式是一直在为开发者出货罐子作为一个单独的神器。看到这个问题和相关的答案