简体   繁体   English

在我的项目中包括外部jar文件

[英]Include the external jar files in my project

I'm developing a Java SE application with Netbeans IDE. 我正在使用Netbeans IDE开发Java SE应用程序。 I added external jar files to the project. 我向项目添加了外部jar文件。 After my project is compiled, these external jar files will be in the lib folder, next to the jar file. 编译我的项目后,这些外部jar文件将位于jar文件旁边的lib文件夹中。

I want to use jar in jar solution. 我想在jar解决方案中使用jar。 So the external jar files are included in my project's runnable jar file. 因此,外部jar文件包含在我的项目的可运行jar文件中。

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. 我很确定Java不支持嵌入式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. 我建议将lib移至文件系统(以便在与可执行文件Jar相同的目录中创建一个子文件夹./lib,看看是否有区别。

If you really want to use embedded Jars, you could take a read of One-Jar 如果您真的想使用嵌入式Jars,可以阅读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™ ; 您可能想尝试One-JAR™ and if your project is Maven-based : 并且如果您的项目是基于Maven的

<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>

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

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