[英]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.