我想在我的Maven項目中安裝和使用第三方Jar。
第一罐是:使用Maven安裝第三方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
我試圖修復它安裝缺少的瓶子:
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>
但是從包導入類根本不工作,我不斷收到同樣的例外。 我想這是因爲我沒有正確安裝罐子。 我根據對我有意義的情況填充了-DgroupId
& -DartifactId
,但我不確定是否填寫了正確的值。
所以你得到一個運行時異常,而不是編譯時錯誤? 這可能是起訴到沒有在運行時類路徑上的jar – jr593
是的,這是一個運行時異常。它正好在我使用'com.urbancode.anthill3.main.client.AnthillClient'類的類中失敗。 –