How to exclude Jars from being added in the WAR file

拥有回忆 提交于 2019-12-08 19:17:39

问题


In the my application I have set some jars as project dependency. This jars are added as User Library. As I am running the application in JBoss AS7 and I am using the JSF implementation which is provided by the JBoss server, I have copied those JSF jars from the module and create a new User Library namely JBoss JSF. This library has been used to create JSF 2 Dynamic Web Project in Eclipse. Now when I am exporting it as a WAR file, those jsf jars are automatically being copied and added in /WEB-INF/lib of the war. I don't want that these files are added as they are already present in the container.

Is there any way to do it?

For more information, this is the content of the .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/common"/>
    <classpathentry kind="src" path="src/service"/>
    <classpathentry kind="src" path="src/web"/>
    <classpathentry kind="src" path="src/persistent"/>
    <classpathentry kind="src" path="src/dao"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JBoss JSF">
        <attributes>
            <attribute name="owner.project.facets" value="jst.jsf"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JBoss Servlet"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JBoss log4j"/>
    <classpathentry kind="output" path="build/classes"/>
</classpath>

The Deployment Assembly of my application:


回答1:


Try this

  1. Open Project properties
  2. Select Deployment Assembly
  3. Select libraries that you need to exclude from the war file then click Remove . Jars you selected will be removed from the War file

or try to add one more attribute to the .classpath file

<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JBoss JSF">

   <attributes>

    <attribute name="owner.project.facets" value="jst.jsf"/>

    <attribute name="org.eclipse.jst.component.nondependency" value=""/> 

  </attributes>




回答2:


  1. Open the Project Properties Dialog.
  2. Select Java Build Path from the left panel.
  3. Select Source Tab.
  4. A list of all Jars included in the project will be listed.
  5. Select the JAR file and click edit button.
  6. In the included or excluded pattern window, choose excluded (If that's what you want) and add a pattern. Select Ok.
  7. In each row of the jar's, at the right hand side you will see a plus or minus sign accordingly.



回答3:


you can set the scope of the dependency to provided. ndicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive. A dependency with this scope will not be included in wars/ears.

 <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
        <scope>provided</scope>
    </dependency>


来源:https://stackoverflow.com/questions/13950012/how-to-exclude-jars-from-being-added-in-the-war-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!