[英]Installing 3rd Party Jar with Maven
我正在尝试在我的Maven项目中安装和使用3rd Party Jars。
第一个Jar是:
anthill3-client.jar中
这是他的结构:
├───com
│ └───urbancode
│ ├───anthill3
│ │ ├───command
│ │ ├───custom
│ │ ├───dashboard
│ │ ├───domain
│ │ └───wsviewer
│ ├───codestation2
│ │ ├───domain
│ │ └───server
│ ├───commons
│ │ ├───db
│ │ ├───logfile
│ │ └───util
│ ├───license
│ ├───persistence
│ │ └───collections
│ └───scripting
└───META-INF
我通过运行以下命令进行安装:
call mvn install:install-file -Dfile=anthill3-client.jar -DgroupId=com.urbancode -DartifactId=anthill3-client -Dversion=1.0 -Dpackaging=jar
在pom.xml中配置了它:
<dependency>
<groupId>com.urbancode</groupId>
<artifactId>anthill3-client</artifactId>
<version>1.0</version>
</dependency>
并能够通过导入一些类在我的代码中使用它:
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
:
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
他的结构:
├───com
│ └───urbancode
│ ├───command
│ │ ├───shell
│ │ └───var
│ ├───commons
│ │ └───util
│ ├───devilfish
│ │ ├───client
│ │ ├───common
│ │ ├───server
│ │ └───services
│ └───plugin
└───META-INF
通过运行以下命令进行安装:
call mvn install:install-file -Dfile=devilfish.jar -DgroupId=com.urbancode -DartifactId=devilfish -Dversion=1.0 -Dpackaging=jar
并添加到我的pom中:
<dependency>
<groupId>com.urbancode</groupId>
<artifactId>devilfish</artifactId>
<version>1.0</version>
</dependency>
但是从Package导入类根本行不通,而且我不断遇到同样的异常。 我猜是因为我没有正确安装Jars而发生的。 我根据对我有意义的内容填充了-DgroupId
和-DartifactId
,但是我不确定我是否填充了正确的值。
不确定您如何运行项目,但是在编译时可以正常运行,并且运行时失败,因此我猜您在构建jar时不正确。
为了使jar与依赖关系一起打包,请遵循以下步骤: 如何使用Maven创建具有依赖关系的可执行JAR?
<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>
打开devilfish.jar(使用压缩工具),然后移至META-INF / maven / [several-packages] /pom.xml。 打开其pom.xml并查找正确的组,工件名称和版本。 然后使用适当的设置再次安装。 如果您的公司是urbancode,请为您的公司安装Artifactory或Nexus服务器,在其中发布文件,然后将此服务器添加到pom.xml中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.