简体   繁体   English

将外部库与不可执行的Jar相关联

[英]Associate external libraries with Non Executable Jar

I have created class file which has dependencies to other external jars. 我创建了具有对其他外部jar依赖项的类文件。 I have generated a non executable jar for my program and I am using class loader to access methods in my jar file. 我已经为程序生成了一个不可执行的jar,并且正在使用类加载器访问jar文件中的方法。 But my call is failing with NoClassfoundException on dependent jars. 但是我的调用失败,并在依赖的jar上出现了NoClassfoundException。 Dependent jars are placed in the same location as my jar file that I am trying to load using classloader. 依赖的jar放置在与我尝试使用classloader加载的jar文件相同的位置。

a. 一种。 Is there anything more I need to do to associated the external jar files. 我还需要做更多的事情来关联外部jar文件。 b. Is there any other option get this done without having to convert my jar file to executable jar. 是否有其他选择可以完成此任务,而不必将我的jar文件转换为可执行jar。

Try using the following pom.xml I actually used it to make a single executable jar but I modified it now for non-executable 尝试使用以下pom.xml,我实际上是用它来制作一个可执行的jar,但现在我将其修改为不可执行

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ga</groupId>
<artifactId>GAChainMR</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
......
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <!-- Skip the tests run. -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>

        <!-- Sources generation -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
             </configuration>
            </plugin>
    </plugins>
</build>

I build the jar using mvn package command and found all the dependencies in a jar, try and let me know. 我使用mvn package命令构建了jar,并在jar中找到了所有依赖项,请尝试让我知道。 Add depencies for the external jars in the above pom 在上面的pom中为外部罐子添加依赖

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM