Java 使用Maven安装第三方Jar

Java 使用Maven安装第三方Jar,java,maven,jar,Java,Maven,Jar,我正试图在Maven项目中安装和使用第三方JAR。 第一个罐子是: anthill3 client.jar 这就是他的结构: ├───com │ └───urbancode │ ├───anthill3 │ │ ├───command │ │ ├───custom │ │ ├───dashboard │ │ ├───domain │ │ └───wsviewer │ ├───codesta

我正试图在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>
但它并没有完全起作用,因为我得到了
。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来修复它:

魔鬼鱼.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>

com.urbancode
魔鬼鱼
1
但是从包中导入类根本不起作用,我不断得到同样的异常。 我想这是因为我没有正确安装罐子。
我根据对我有意义的内容填写了
-DgroupId
&
-DartifactId
,但我不确定我是否填写了正确的值。

不确定您是如何运行项目的,但编译时间没有问题,运行时间也没有问题,所以我猜您没有正确构建jar

为了将jar打包为依赖项,请执行以下操作:


maven汇编插件
完全合格
带有依赖项的jar

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

那么您得到的是运行时异常,而不是编译时错误?这可能是因为jar不在运行时类路径上是的,这是一个运行时异常。它正好在我使用
com.urbancode.anthill3.main.client.AnthillClient
类中的类时失败。META-INF不包含pom.xml。仅MANIFEST.MF包含以下内容:
MANIFEST版本:1.0
Ant版本:ApacheAnt 1.9.7
创建人:pxa6460sr16-20140418_01(SR16)(IBM公司)
我不认为JAR是用Maveni构建的,它里面没有“maven”文件夹吗?应位于此文件夹结构中。如果不是,那就不是Maven神器,也不是Maven神器。但不知怎的,我能够从其中一个调用一个方法,甚至可以在maven中使用不是用maven构建的Jar吗?请看这里:是的,没关系,如果你可以使用它的API,这意味着你拥有它。问题是在运行时,当应用程序查找第三方jar但找不到它时。如果你能在答案中添加所有必要的信息,那就更好了。不建议添加链接,因为它们可能会被破坏,或者以后可能会更改内容。
<dependency>
  <groupId>com.urbancode</groupId>
  <artifactId>devilfish</artifactId>
  <version>1.0</version>
</dependency>
<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>