问题
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
- Open Project properties
- Select Deployment Assembly
- 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:
- Open the Project Properties Dialog.
- Select Java Build Path from the left panel.
- Select Source Tab.
- A list of all Jars included in the project will be listed.
- Select the JAR file and click edit button.
- In the included or excluded pattern window, choose excluded (If that's what you want) and add a pattern. Select Ok.
- 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