eclipse 在 Maven 项目中添加外部 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33522428/
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
Adding external jar in a maven project
提问by WantIt
I have a maven project (I use the jersey template, since I'll be creating an API) and would like to add an external jar file. I tried to follow this reference here
我有一个 maven 项目(我使用 jersey 模板,因为我将创建一个 API)并且想添加一个外部 jar 文件。我试图在这里遵循这个参考
I'm using Eclipse Mars in Windows environment. I added the following depedency to my pom.xml file
我在 Windows 环境中使用 Eclipse Mars。我在 pom.xml 文件中添加了以下依赖项
Now, when I try to use the jar file in my application, why is that I can't access it? The classes in the jar file couldn't be resolved.
现在,当我尝试在我的应用程序中使用 jar 文件时,为什么我无法访问它?无法解析 jar 文件中的类。
回答by JJF
I sometimes use file system based repos for this kind of thing.
我有时会使用基于文件系统的 repos 来处理这种事情。
<repositories>
<repository>
<id>local-files</id>
<name>local-files</name>
<url>file://c:\test\filerepo</url>
</repository>
</repositories>
Then you can install files into the file repo...
然后您可以将文件安装到文件仓库中...
mvn install:install-file -Dfile=onebusaway-gtfs-1.3.3 -DgroupId=org.onebusaway.gtfs -DartifactId=onebusaway-gtfs-1.3.3 -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=c:\test\filerepo
Just include the above <repoisitory>
entry into any pom you want to have access to the file repo. For example:
只需将上述<repoisitory>
条目包含在您想要访问文件 repo 的任何 pom 中。例如:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>some-artifact</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>local-files</id>
<name>local-files</name>
<url>file://c:\test\filerepo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.onebusaway.gtfs</groupId>
<artifactId>org-onebusaway-gtfs-1.3.3</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>