[英]Adding external jar in a maven project
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.我有一个 maven 项目(我使用 jersey 模板,因为我将创建一个 API)并且想添加一个外部 jar 文件。 I tried to follow this reference here我试图在这里遵循这个参考
I'm using Eclipse Mars in Windows environment.我在 Windows 环境中使用 Eclipse Mars。 I added the following depedency to my pom.xml file我在 pom.xml 文件中添加了以下依赖项
Now, when I try to use the jar file in my application, why is that I can't access it?现在,当我尝试在我的应用程序中使用 jar 文件时,为什么我无法访问它? The classes in the jar file couldn't be resolved.无法解析 jar 文件中的类。
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.只需将上述<repoisitory>
条目包含在您想要访问文件 repo 的任何 pom 中。 For example:例如:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.