Maven 构建 Java 我的项目
Maven 应用原型 archetype 插件创立我的项目。要创立一个简略的 Java 利用,咱们将应用 maven-archetype-quickstart 插件。

在上面的例子中,咱们将在 C:\MVN 文件夹下创立一个基于 maven 的 java 利用我的项目。

命令格局如下:

mvn archetype:generate "-DgroupId=com.companyname.bank" "-DartifactId=consumerBanking" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DinteractiveMode=false"
参数阐明:

-DgroupId: 组织名,公司网址的反写 + 项目名称
-DartifactId: 我的项目名-模块名
-DarchetypeArtifactId: 指定 ArchetypeId,maven-archetype-quickstart,创立一个简略的 Java 利用
-DinteractiveMode: 是否应用交互模式
生成的文件夹构造如下:
各个文件夹阐明:

在 C:\MVN\consumerBanking\src\main\java\com\companyname\bank 文件夹中,能够看到一个 App.java,代码如下:

App.javapackage com.companyname.bank; /** * Hello world! * */public class App {    public static void main( String[] args )    {        System.out.println( "Hello World!" );    }}

关上 C:\MVN\consumerBanking\src\test\java\com\companyname\bank 文件夹,能够看到 Java 测试文件 AppTest.java。

AppTest.javapackage com.companyname.bank; import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite; /** * Unit test for simple App. */public class AppTest extends TestCase {    /**     * Create the test case     *     * @param testName name of the test case     */    public AppTest( String testName )    {        super( testName );    }     /**     * @return the suite of tests being tested     */    public static Test suite()    {        return new TestSuite( AppTest.class );    }     /**     * Rigourous Test :-)     */    public void testApp()    {        assertTrue( true );    }}

接下来的开发过程中咱们只须要依照下面表格中提到的构造搁置好,其余的事件 Maven 帮咱们将会搞定。