Java Maven 本地依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23356056/
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
Maven Local Dependency
提问by PandaBearSoup
I have a jar included under src/libs. This is necessary because when I run my application on the intended server it will not be able to download external dependencies. I am receiving the following error when building from the command line: NoClassDefFoundError. The dependency in my pom:
我在 src/libs 下包含一个 jar。这是必要的,因为当我在目标服务器上运行我的应用程序时,它将无法下载外部依赖项。从命令行构建时,我收到以下错误:NoClassDefFoundError。我的 pom 中的依赖项:
<dependency>
<groupId>jFuzzyLogic_core</groupId>
<artifactId>jFuzzyLogic_core</artifactId>
<scope>system</scope>
<version>2.0.7</version>
<systemPath>${basedir}\src\libs\jFuzzyLogic_core.jar</systemPath>
</dependency>
I have read conflicting posts on whether or not this is correct and I can not figure out what to do.
我已经阅读了关于这是否正确的相互矛盾的帖子,我不知道该怎么做。
The command line as requested:
命令行按要求:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/jFuzz
yLogic/FIS
at noobbot.Main.<init>(Main.java:41)
at noobbot.Main.main(Main.java:30)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.jFuzzyLogic.FIS
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Also relevant,
也有关系,
[WARNING] 'dependencies.dependency.systemPath' for jFuzzyLogic_core:jFuzzyLogic_
core:jar should not point at files within the project directory, ${basedir}\src\
libs\jFuzzyLogic_core.jar will be unresolvable by dependent projects @ line 24,
column 22
can anyone else suggest how to do this if this is in fact not the correct way?
如果这实际上不是正确的方法,其他人可以建议如何做到这一点吗?
采纳答案by gaganbm
Try specifying your lib directory as a repository in your pom.xml
:
尝试将您的 lib 目录指定为您的pom.xml
:
<repository>
<id>project_lib</id>
<name>Repository in project's lib dir</name>
<layout>default</layout>
<url>file:///${project.basedir}/lib</url>
</repository>
Then in dependency I don't think you'll need to add <systemPath>
for that Jar.
然后,我认为您不需要<systemPath>
为该 Jar添加依赖项。
回答by Ayman
In such cases, I normally import the JAR file into the local repository. You can use this command:
在这种情况下,我通常将 JAR 文件导入本地存储库。你可以使用这个命令:
mvn install:install-file -Dfile=name-of-your-jar.jar -DgroupId=your-group-id -DartifactId=your-artifact-id -Dversion=your-version -Dpackaging=jar
So, if we take the snippet you put, the command will be:
因此,如果我们采用您放置的代码段,命令将是:
mvn install:install-file -Dfile=commons-validator-1.4.0.jar -DgroupId=jFuzzyLogic_core -DartifactId=jFuzzyLogic_core -Dversion=2.0.7 -Dpackaging=jar
Once done, you can setup the dependance without any system path.
完成后,您可以在没有任何系统路径的情况下设置依赖项。