首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Maven安装第三方Jar

用Maven安装第三方Jar
EN

Stack Overflow用户
提问于 2017-06-14 10:57:28
回答 2查看 753关注 0票数 0

我试图在我的Maven项目中安装和使用第三方Jars。

第一个罐子是:

anthill3-client.jar

这就是他的结构:

代码语言:javascript
复制
├───com
│   └───urbancode
│       ├───anthill3
│       │   ├───command
│       │   ├───custom
│       │   ├───dashboard
│       │   ├───domain
│       │   └───wsviewer
│       ├───codestation2
│       │   ├───domain
│       │   └───server
│       ├───commons
│       │   ├───db
│       │   ├───logfile
│       │   └───util
│       ├───license
│       ├───persistence
│       │   └───collections
│       └───scripting
└───META-INF

我通过运行以下命令来安装它:

代码语言:javascript
复制
call mvn install:install-file -Dfile=anthill3-client.jar -DgroupId=com.urbancode -DartifactId=anthill3-client -Dversion=1.0 -Dpackaging=jar

在pom.xml中配置它:

代码语言:javascript
复制
<dependency>
  <groupId>com.urbancode</groupId>
  <artifactId>anthill3-client</artifactId>
  <version>1.0</version>
</dependency>

并且能够通过导入一些类在我的代码中使用它:

代码语言:javascript
复制
import com.urbancode.anthill3.domain.persistent.PersistenceException;
import com.urbancode.anthill3.domain.security.AuthorizationException;
import com.urbancode.anthill3.main.client.AnthillClient;
import com.urbancode.anthill3.persistence.UnitOfWork;
import com.urbancode.anthill3.domain.project.*;

不过,它不太管用,因为我得到了.ClassNotFoundException

代码语言:javascript
复制
Exception in thread "main" java.lang.NoClassDefFoundError: com/urbancode/devilfish/services/method/MethodCall
    at Valor.CM.Tools.App.main(App.java:26)
Caused by: java.lang.ClassNotFoundException: com.urbancode.devilfish.services.method.MethodCall
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

我试图通过安装丢失的Jar来修复它:

devilfish.jar

他的结构:

代码语言:javascript
复制
├───com
│   └───urbancode
│       ├───command
│       │   ├───shell
│       │   └───var
│       ├───commons
│       │   └───util
│       ├───devilfish
│       │   ├───client
│       │   ├───common
│       │   ├───server
│       │   └───services
│       └───plugin
└───META-INF

通过运行以下命令安装它:

代码语言:javascript
复制
call mvn install:install-file -Dfile=devilfish.jar -DgroupId=com.urbancode -DartifactId=devilfish -Dversion=1.0 -Dpackaging=jar

并添加到我的pom中:

代码语言:javascript
复制
<dependency>
  <groupId>com.urbancode</groupId>
  <artifactId>devilfish</artifactId>
  <version>1.0</version>
</dependency>

但是从包中导入类根本不起作用,而且我一直得到同样的异常。我想是因为我没把罐子装好。我根据对我来说有意义的内容填充了-DgroupId & -DartifactId,但我不确定我是否填写了正确的值。

EN

回答 2

Stack Overflow用户

发布于 2017-06-14 11:05:21

不确定您是如何运行项目的,但编译时没有问题,运行时失败,所以我想您没有正确地构建jar。

为了将jar打包成依赖项,请遵循以下代码:How can I create an executable JAR with dependencies using Maven?

代码语言:javascript
复制
<build>
 <plugins>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>fully.qualified.MainClass</mainClass>
        </manifest>
      </archive>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
  </plugin>
 </plugins>
</build>
票数 0
EN

Stack Overflow用户

发布于 2017-06-14 11:11:34

打开devilfish.jar (使用压缩工具)并移动到META/maven/多个-packages/put.xml。打开它的pom.xml并查找正确的组、工件名称和版本。然后用适当的设置重新安装它。如果urbancode是您的公司,请为您的公司安装Artifactory或Nexus服务器,在那里发布文件并将此服务器添加到您的pom.xml中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44542838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档