java - 在maven项目中添加外部jar

标签 java eclipse maven jar

我有一个 Maven 项目(我使用 Jersey 模板,因为我将创建一个 API)并且想要添加一个外部 jar 文件。我试图遵循这个reference here

enter image description here

我在 Windows 环境中使用 Eclipse Mars。我将以下依赖项添加到我的 pom.xml 文件中

enter image description here

现在,当我尝试在应用程序中使用 jar 文件时,为什么我无法访问它?无法解析 jar 文件中的类。

enter image description here

最佳答案

我有时会使用基于文件系统的存储库来处理此类事情。

<repositories>
   <repository>
    <id>local-files</id>
    <name>local-files</name>
    <url>file://c:\test\filerepo</url>
   </repository>
</repositories>

然后您可以将文件安装到文件存储库中...

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

只需包含上面的 <repoisitory>进入您想要访问文件存储库的任何 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>

关于java - 在maven项目中添加外部jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33522428/

相关文章:

twitter-bootstrap - 如何在 Vaadin 14 应用程序中包含自定义 SASS 文件?

java - 如何编写单元测试来涵盖抛出 IOException 的情况?

java - 当用户登录时,来自 Firebase 数据库的评论电子邮件为空

java - 返回/打印数组

eclipse - 有人知道 APEX 重构工具吗?

Android:2.1 并为 2.2+ 用户安装 SD 卡功能

c++ - Eclipse自动在main方法处加断点

android - 在项目中使用android swipelistview

java - 概念验证:如何在Java中使用反射来动态选择可用的构造函数

java - Spring Boot jar 中的 FileNotFoundException 但文件存在