为什么我不能在WEB-INF之外打包某些JAR [英] Why can't I pack certain JARs outside WEB-INF

查看:110
本文介绍了为什么我不能在WEB-INF之外打包某些JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一些博客中读到,不建议(或不可能)将jar打包在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中的jar,例如:

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无法加载的错误.但是,当我将库手动移到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文件夹和所有jar打包到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?? OR Why 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(复制依赖项)将所有依赖项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能够从库中提取所有jar.

So, now the index.jsp is able to fetch all the jars from the lib.

这篇关于为什么我不能在WEB-INF之外打包某些JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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