Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude Jars from being added in the WAR file

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: enter image description here

like image 251
Tapas Bose Avatar asked Dec 19 '12 10:12

Tapas Bose


People also ask

How do I exclude a war file?

It is possible to include or exclude certain files from the WAR file, by using the <packagingIncludes> and <packagingExcludes> configuration parameters. They each take a comma-separated list of Ant file set patterns.

How do I exclude a jar from a POM file?

We can have multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependencies we want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom.

Does war file contain all dependencies?

war file have all the needed . jar's to run in a container in a different physical server (but same software i.e. apache tomcat).

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.


Video Answer


1 Answers

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>

like image 199
Rahul Avatar answered Oct 04 '22 13:10

Rahul