maven - 使用 Maven 在瘦 WAR 中包含特定的 JAR 文件

标签 maven jar war ear

我在使用 WAR 模块时遇到了一些问题,并且难以加载标签库。我一直收到这个异常:

JSPG0047E: Unable to locate tag library for uri http://www.springframework.org/tags/form 
    at com.ibm.ws.jsp.translator.visitor.tagfiledep.TagFileDependencyVisitor.visitCustomTagStart(TagFileDependencyVisitor.java:76)
    at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:366)
    at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
    at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
...

After a bit of searching, I found a lot of suggestions that the spring jars need to be on the application's classpath. I checked in my EAR's lib folder and sure enough, spring-web and spring-webmvc were there.

It should be noted that the EAR is built with skinny WARs - since they use most of the same libraries, all library files are in MyAppEAR/lib instead of MyAppEAR/MyWAR1/WEB-INF/lib, MyAppEAR/MyWAR2/WEB-INF/lib, MyAppEAR/MyWAR3/WEB-INF/lib, etc...

I did finally manage to resolve this missing taglib error, but I had to move spring-web and spring-webmvc to MyAppEAR/MyWAR1/WEB-INF/lib.

So I have a couple of questions:

  1. Is this the only way to fix this problem?
  2. If so, how can I build a sort-of skinny WAR using maven? Currently, the EAR part of the POM looks like this:

    <plugin>
      <artifactId>maven-ear-plugin</artifactId>
      <version>2.8</version>
      <configuration>
        <applicationName>MyAppEAR</applicationName>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
        <skinnyWars>true</skinnyWars>
    

我想我可以关闭 skinny WAR,然后采取一些其他步骤从 WAR 文件中删除所有库并将它们复制到 MyAppEAR/lib except 用于 spring web jar,但我希望有更好的解决方案。

最佳答案

我自己也有同样的问题 - 当我的 spring JAR 文件在我的 ear/lib 文件夹中时,我无法访问 Spring 或 Sitemesh 的 TLD!

在 MANIFEST 中包含类路径导致我的应用服务器失控(因为所有依赖项都被加载了两次)。

(是的,我还在我的 maven-ear-plugin 中将 skinnyWars 设置为 true)。

我可以解决这个问题的唯一方法是将 Springsitemesh 包含在 maven-war-plugin 中配置:

<packagingExcludes>%regex[WEB-INF/lib/(?!spring|sitemesh).*.jar]</packagingExcludes>

这不是最优雅的解决方案,但我能找到的破坏性最小的解决方案。

这是我的完整配置:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>

                <!--
                Q. Why is this set?
                A. maven-ear-plugin in our EAR modules have `skinnyWars` enabled to that WAR files 
                   would not include any third-party libraries in the WAR's WEB-INF/lib folder, however 
                   this does not work for ejbs (like our own EJB modules).

                   We'll need to exclude them from here anyway (except for a few select JARS)...
                -->                 
                <packagingExcludes>%regex[WEB-INF/lib/(?!spring|sitemesh).*.jar]</packagingExcludes>

                <archive>
                    <manifest>
                        <addClasspath>false</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

附言。我的设置是 JBoss EAP 6.x 和一个包含多个 EJB、WAR 和第三方 JAR 的 ear 文件。

关于maven - 使用 Maven 在瘦 WAR 中包含特定的 JAR 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19800584/

相关文章:

java - 使用 spring 的简单嵌入式数据库

java - 根据其他属性的存在设置 Maven 属性

java - 如何在我的小程序中加载并显示远程 jar 小程序?

java - Gradle:如何将 servlet JARS 复制到 WAR 文件中的文件夹?

tomcat - 部署为 WAR 或在 Tomcat 下运行时出现 UTF-8 问题

maven - 无法从 key 环文件 secring.gpg 中检索 key ,因为它不存在

eclipse - JRebel 可以重新部署 Maven 依赖项中的更改吗?

apache - 当tomcat中的 war 停止时如何自动重定向到另一个页面

java - 创建 .jar 和 FileNotFoundException

java - 在 IntelliJ IDEA 中创建可执行 jar