问题描述
我在几篇博客中读到,不建议(或不可能)将 jars 打包到 WEB-INF 文件夹之外.我很好奇为什么会这样..
I have read in several blogs that it is not advised (or not possible)to pack jars outside the WEB-INF folder. I am curious as to know why this is so..
例如,
mainStuff.war
|
|-->WEB-INF
| |
| |-->lib (having many jars, used by the contents of specificStuff.jar
| |-->classes
| |-->web.xml
|
|-->META-INF (having the .MF file and signed files .SF and .DSA)
|
|
|-->index.jsp (consists of a jnlp xml, referring to the jars in lib)
|
|
|-->specificStuff.jar (this is a separate jar module, which is mentioned in the POM of the war)
在 index.jsp 中的 jnlp 配置中,我指的是 lib 中的 jars,例如:
In the jnlp configuration in index.jsp, i am referring to the jars in lib like:
<resources>
<java version="1.6+"/>
<jar href="specificStuff.jar"/>
<jar href="lib/someJarthatIneed.jar"/>
</resources>
现在,当我启动 JNLP 时,出现 someJarthatIneed 加载失败的错误.但是,当我手动将 lib 移到 WEB-INF 之外时,没有发生此错误.
Now, when i launch my JNLP, I get the error that someJarthatIneed failed to load. However, when i manually moved the lib outside WEB-INF, this error did not occur.
那么,我需要知道的是,有没有办法将 lib 文件夹和所有 jars 打包到 WEB-INF 之外??或者为什么我的 jnlp(在 WEB-INF 之外)无法从 WEB-INF/lib 加载 jar.(我尝试将 jar 的路径更改为
So, what I need to know is that, is there any way to pack the lib folder and all jars outside WEB-INF??ORWhy is it that my jnlp (which is outside WEB-INF) not able to load the jar from WEB-INF/lib.(I tried changing the path of jar as
<jar href="WEB-INF/lib/someJarthatIneed.jar"/>
但它也不起作用..)
对此的任何帮助都将得到认可.:)
Any help on this will be apprciated. :)
推荐答案
感谢所有建议...但是,我找到了解决方案...
Thanks for all the suggestions... But, I found a way to do it..
我使用maven-dependency-plugin(copy-dependencies)把所有的依赖jar包复制到一个文件夹lib下到指定位置.
I used the maven-dependency-plugin (copy-dependencies) to copy all the dependency jars to a folder lib to a specified location.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/webapp/lib</outputDirectory>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
然后使用
<packagingExcludes>WEB-INF/lib/</packagingExcludes>
在 pom 中,您使用 maven-war-plugin 进行战争,从 WEB-INF 中删除 lib 文件夹..
in the pom, where you are using maven-war-plugin to make the war, to remove the lib folder from WEB-INF..
所以,现在 index.jsp 能够从 lib 中获取所有的 jar.
So, now the index.jsp is able to fetch all the jars from the lib.
这篇关于为什么我不能在 WEB-INF 之外打包某些 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!