开始使用Maven [英] Get started with maven

查看:180
本文介绍了开始使用Maven的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在蚂蚁,如何开始使用Maven的经验。与Maven超过蚂蚁什么优势?

I have experience in Ant, how to get started with maven. Any advantage with maven over ant?

推荐答案

有一个相当大的差异,在蚂蚁的力量,您可以创建自己的目标,你会得到一个对Maven目标的默认设置,例如清洁,安装包等没有脚本他们。

There's a quite large difference, where ant forces you to create your own targets you will get a default set of targets for maven, e.g., clean, install, package etc without scripting them.

Maven的提升你使用一个共同的目录结构Java类,资源等,如果你这样做,Maven是只是 XML 文件,您可以指定一些项目的元数据,如名称,最重要的depenencies。它提供了类似的依赖性查找到蚂蚁什么常春藤一样。

Maven promotes that you use a common directory structure for java classes, resources etc. If you do, maven is just on xml file where you specify some project metadata such as name, package and most importantly depenencies. It provides similar dependency lookup to what ivy does for ant.

根据标准Maven的提升,它变得非常容易为开发商接近,建立自己的项目。有了一个IDE如的Netbeans 这足以选择打开项目,然后按安装按钮来编译,并在您的本地存储库安装工程。

Based on the standard maven promotes, it becomes very easy for developers to approach and build your projects. With an IDE such as Netbeans it's enough to select open project, and then hit the install button to compile and install the project in your local repository.

我建议使用Maven Maven的方式。不同的事情往往会导致更多的痛苦比它的价值。提供的Maven插件结构,其中您需要时可以执行多种任务,如调用Ant库。如果你正在积极与多个项目(并希望项目切换到尽可能容易)Maven是一个巨大的飞跃,特别是如果与资料库的服务器相结合,如的Nexus Archiva

I recommend working with maven the maven way. Doing things differently will often cause more pain than it's worth. Maven offers a plugin structure where you can perform various tasks, such as invoke the ant-library should you need to. If you're actively working with multiple projects (and want project switching to be as easy as possible) maven is a huge leap forward, especially if combined with repository server such as Nexus or Archiva.

要么你可以使用Maven的原型目标生成您的项目结构,或者你可以做我通过复制考取一个空模板项目,每次做的方式。然后,你需要maven的二进制和项目定义文件的pom.xml 我通常还会在项目之间复制粘贴。

Either you can generate your project structure using the archetype goal of maven, or you could do it the way I do by copy-pasing an empty template project every time. Then you need the maven binary and the project definition file pom.xml which I typically also copy paste between projects.

一个样本包含下面。有了这个例子中,你会得到外部库的log4j,并自动获得所有nececcities构建和打包自己的项目(在这种情况下一个 JAR 文件)。

A sample is included below. With this sample you'll get the external library log4j, and you automatically get all nececcities to build and package your own project (in this case to a jar file).

<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>
    <groupId>com.company</groupId>
    <artifactId>projectname</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0-SNAPSHOT</version>
    <name>${project.artifactId}</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    <!-- add more dependencies here ... -->
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

这篇关于开始使用Maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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