如何使用 Ant 构建在 war 文件中包含 Maven 依赖库 [英] How to include maven dependency libraries in war file using Ant build

查看:24
本文介绍了如何使用 Ant 构建在 war 文件中包含 Maven 依赖库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在通过 ant 构建 WAR 文件时包含 maven 依赖文件.这是 pom.xml.我尝试了多种解决方案,包括执行等,但没有任何效果.

I'm trying to include the maven dependencies files while build WAR file through ant. Here is the pom.xml. I've tried multiple solutions including executions etc but nothing works.

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CustomerPortal</groupId>
<artifactId>CustomerPortal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

        <!-- <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> 
            <configuration> <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> 
            </configuration> </plugin> -->

    </plugins>
</build>
<repositories>
    <repository>
        <id>ZK CE</id>
        <name>ZK CE Repository</name>
        <url>http://mavensync.zkoss.org/maven2</url>
    </repository>
</repositories>
<dependencies>

    <!-- Log4j starts -->

    <!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> 
        <version>2.0.2</version> </dependency> -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>2.0.2</version>
    </dependency>

    <!-- Log4j ends -->

    <!-- ZK starts -->

    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkplus</artifactId>
        <version>7.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zhtml</artifactId>
        <version>7.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkbind</artifactId>
        <version>7.0.2</version>
    </dependency>
    <!-- <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zkmax</artifactId> 
        <version>6.5.2</version> </dependency> -->
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zul</artifactId>
        <version>7.0.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.4</version>
    </dependency>

    <!-- ZK ends -->

    <!-- Hibernate starts -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.1.Final</version>
        <classifier>tests</classifier>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.1.0.CR2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>2.5.1</version>
    </dependency>
    <!-- Hibernate end -->

    <!-- Email Api starts -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>
    <!-- Email Api ends -->
    <!-- Time API starts -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
    <!-- Time API ends -->

    <!-- BeanUtils Api starts -->
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.7.0</version>
    </dependency>
    <!-- BeanUtils Api ends -->


    <!-- MYSQL Driver starts -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
    <!-- MYSQL Driver ends -->




</dependencies>

这是我的 build.xml 文件.一切正常,但我希望所有依赖文件都在我的 WAR 文件中

Here is my build.xml file. Every thing is working fine but I want all dependencies file in my WAR file

    <?xml version="1.0" encoding="UTF-8"?>
<project name="MedGulfCustomerPortal" default="war" basedir=".">

    <property name="project-name" value="${ant.project.name}" />
    <property name="war-file-name" value="${project-name}.war" />
    <property name="source-directory" value="src" />
    <property name="main-web-directory" value="WebContent" />
    <property name="web-directory" value="WebContent/WEB-INF" />
    <property name="web-xml-file" value="WebContent/WEB-INF/web.xml" />
    <property name="build-directory" value="build" />
    <property name="dir.classes" value="WebContent/WEB-INF/classes" />

    <tstamp prefix="build-info">
        <format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
        <format property="current-time" pattern="hh:mm:ss a z" locale="en" />
    </tstamp>
    <path id="maven-ant-tasks.classpath" path="WebContent/WEB-INF/lib/maven-ant-tasks-2.1.3.jar" />
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />


    <!-- <javac debug="on" srcdir="${source-directory}" destdir="${dir.classes}" includes="**/*" includeantruntime="false">
            <classpath refid="maven-ant-tasks.classpath" />
        </javac>
    -->
    <target name="war" depends="">
        <mkdir dir="${build-directory}" />
        <delete file="${build-directory}/${war-file-name}" />
        <war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
            <zipfileset dir="${main-web-directory}" includes="**/*zul" />
            <zipfileset dir="${web-directory}" includes="**" prefix="WEB-INF" />
            <zipfileset dir="${source-directory}" includes="**/*java" prefix="WEB-INF/classes" />
            <manifest>
                <attribute name="Built-By" value="${builder}" />
                <attribute name="Built-On" value="${build-info.current-date}" />
                <attribute name="Built-At" value="${build-info.current-time}" />
            </manifest>

        </war>
    </target>

</project>

非常感谢任何帮助.

推荐答案

搜索后我发现如果我把我的依赖文件夹放在 web 部署程序集中.它将从那里复制库.

After searching I found that if I put my dependency folder in on web deployment assembly. It will copy the libraries from there.

这篇关于如何使用 Ant 构建在 war 文件中包含 Maven 依赖库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆