在WAR文件中打包JAR文件 [英] Packaging JAR file in WAR file

查看:124
本文介绍了在WAR文件中打包JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列依赖的Java项目。我想将它们打包成一个JAR文件,以便在我的WAR文件中使用。这些项目依赖于大量的外部库和项目,如log4j,apache-commons等。

I have a series of dependent Java projects. I'd like to package them together into a single JAR file to be used in my WAR file. These projects depend on a large number of external libraries and projects such as log4j, apache-commons etc.

我选择Eclipse中的所有项目并导出为JAR文件,然后将JAR文件复制到我的WAR的/ WEB-INF / lib文件夹中,然后部署我的应用程序。我有以下问题:

I select all the projects in Eclipse and export as a JAR file, then copy the JAR file into my /WEB-INF/lib folder of my WAR, then deploy my application. I have the following problems:


  1. ClassNotFoundException。 Web应用程序找不到打包到我的JAR文件中的库。我通过将所有依赖库移出到/ WEB-INF / lib文件夹并将类路径条目添加到JAR的MANIFEST.MF中来解决了这个问题,这是一个非常痛苦的过程。

  1. ClassNotFoundException. The web application cannot find the libraries packaged into my JAR file. I solved this problem by moving out all the dependent libraries into the /WEB-INF/lib folder and adding class-path entries into the MANIFEST.MF of the JAR, a thoroughly painful process.

JAR文件中的类无法找到JAR中打包的属性文件。我该如何解决这个问题?

The classes in the JAR file cannot find property files packaged inside the JAR. How do I solve this problem?

这些问题是否有标准解决方案?谢谢。

Is there a standard solution for these problems? Thanks.

推荐答案

我建议您使用自动依赖管理的东西。如果您的构建脚本已经安装了ant,那么ivy是一个很好的解决方案。如果您没有构建脚本,maven可能值得研究。

I would recommend using something that does automatic dependency management for you. If you already have ant in place for your build script, ivy is a great solution. If you don't have a build script in place, maven might be worth looking into.

依赖管理会自动为您直接使用的依赖项(jars)提供传递依赖项。

Dependency management automatically pulls in transitive dependencies for dependencies (jars) that you use directly.

这篇关于在WAR文件中打包JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆