开发者

How do I get Maven war plugin copying full jar in /lib of my web application?

开发者 https://www.devze.com 2023-03-15 21:41 出处:网络
I have a web-app configured with a pom.xml. This web-app relies on another maven module that produce a jar file. When i check the produced jar file size it is 8Ko. When i check this same jar file in m

I have a web-app configured with a pom.xml. This web-app relies on another maven module that produce a jar file. When i check the produced jar file size it is 8Ko. When i check this same jar file in my /lib web application, it is 5Ko.

A bunch of classes are simply ignored when the jar file reaches my /lib directory, causing ClassNotFoundException when runing the web application.

Why is my jar trimmed ?

Web-app pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>record</artifactId>
    <groupId>com.company.record</groupId>
    <version>1.0.0</version>
</parent>
<groupId>com.company.record</groupId>
<artifactId>record-webapp</artifactId>
<packaging>war</packaging>
<name>record-webapp</name>
<version>1.0.0</version>

<dependencies>
    <!-- JSF 2.0 -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0.3-b02</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.3-b02</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- Primefaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>2.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency&g开发者_如何学JAVAt;
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>redmond</artifactId>
        <version>1.0.0</version>
    </dependency>

    <!-- Internal dependencies -->
    <dependency>
        <groupId>com.company.record</groupId>
        <artifactId>record-dao</artifactId>
        <version>1.0.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <finalName>record</finalName>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jboss-maven-plugin</artifactId>
            <version>1.5.0</version>
            <configuration>
                <serverName>web</serverName>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>Prime Technology Maven Repository</name>
        <url>http://repository.prime.com.tr</url>
        <layout>default</layout>
    </repository>
</repositories>

record-dao pom.xml

<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>record</artifactId>
    <groupId>com.company.record</groupId>
    <version>1.0.0</version>
</parent>

<groupId>com.company.record</groupId>
<artifactId>record-dao</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>record-dao</name>

<dependencies>
    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.4.Final</version>
        <exclusions>
            <exclusion>
                <artifactId>cglib</artifactId>
                <groupId>cglib</groupId>
            </exclusion>
            <exclusion>
                <artifactId>antlr</artifactId>
                <groupId>antlr</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jta</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
            <exclusion>
                <artifactId>commons-collections</artifactId>
                <groupId>commons-collections</groupId>
            </exclusion>
            <exclusion>
                <artifactId>hibernate-commons-annotations</artifactId>
                <groupId>org.hibernate</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Postgresql -->
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>8.3-606.jdbc4</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- Internal dependencies -->
    <dependency>
        <groupId>com.company.record</groupId>
        <artifactId>record-commun</artifactId>
        <version>1.0.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>


Sounds like perhaps you are looking at different versions of the jar file.

Are you doing a mvn install of the dependent jar before building the webapp project?


I was wondering if it has to do with your dependent jar not being snap shot

Just to prove this point can you go to the local maven repository (not the target directory) on your build machine and delete the current yourdepend-1.0.0.jar file and run mvn install again, I think that should solve your problem (If it is the snap shot issue)


Did you run maven clean package or maven clean install before compiling the war. If you have done package only then the local jar will not be bundled in the war instead the jar in the local repository will be used (which may be old).

the war plugin presumes that web-inf/lib directory jars, don't put any jars there in the lib, manage them through dependency, and change scope accordingly.


I finally find a solution. In the web-app/web-inf/lib directory, there was a jar file who was sharing the same name with the dependent jar file.

For a reason I don't understand, maven-war-plugin used to take this old jar file rather than the freshly one I installed in my local repository.

0

精彩评论

暂无评论...
验证码 换一张
取 消