简体   繁体   中英

Include the external jar files in my project

I'm developing a Java SE application with Netbeans IDE. I added external jar files to the project. After my project is compiled, these external jar files will be in the lib folder, next to the jar file.

I want to use jar in jar solution. So the external jar files are included in my project's runnable jar file.

Is any standard method to solve this problem? Or this is not a good solution?

Thank you!

I'm pretty sure that Java doesn't support embedded Jars. I'd recommend moving the lib out to the file system (so that it creates a sub folder ./lib within the same drctory as your executable Jar & see if that makes a difference.

If you really want to use embedded Jars, you could take a read of One-Jar

You should have a directory structure of

Example below

.\JarTest2.jar

.\lib\log4j-1.2.17.jar

You might wanna try One-JAR™ ; and if your project is Maven-based :

<build>
    <plugins>
        <!-- other plugins omitted for brevity -->
        <plugin>
            <groupId>org.dstovall</groupId>
            <artifactId>onejar-maven-plugin</artifactId>
            <version>1.4.4</version>
            <executions>
                <execution>
                    <configuration>
                        <attachToBuild>true</attachToBuild>
                    </configuration>
                    <goals>
                        <goal>one-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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