发布网友 发布时间:2022-04-20 08:18
共2个回答
热心网友 时间:2023-06-27 10:38
Maven使用原型插件来创建项目。要创建一个简单的Java应用程序,使用maven-archetype-quickstart插件。在下面的例子中,将创建一个基于Maven的Java应用程序项目在C:MVN文件夹。
打开命令控制台,进入到C:MVN目录并执行以下命令mvn命令。
C:MVN>mvn archetype:generate
-DgroupId=com.companyname.bank
-DartifactId=consumerBanking
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
Maven会开始处理,并建立完整的Java应用程序项目结构。
INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] -------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] -------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Batch mode
[INFO] -------------------------------------------------------------------
[INFO] Using following parameters for creating project
from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] -------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.companyname.bank
[INFO] Parameter: packageName, Value: com.companyname.bank
[INFO] Parameter: package, Value: com.companyname.bank
[INFO] Parameter: artifactId, Value: consumerBanking
[INFO] Parameter: basedir, Value: C:MVN
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:MVNconsumerBanking
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------
[INFO] Total time: 14 seconds
[INFO] Finished at: Tue Jul 10 15:38:58 IST 2012
[INFO] Final Memory: 21M/124M
[INFO] ------------------------------------------------------------------
现在去到C:/ MVN目录。将看到创建了一个Java应用程序项目命名consumerBanking(如artifactId规定)。 Maven使用标准的目录结构如下图所示:
用上面的例子中,可以了解到以下关键概念
文件夹结构
描述
consumerBanking contains src folder and pom.xml
src/main/java contains java code files under the package structure (com/companyName/bank).
src/main/test contains test java code files under the package structure (com/companyName/bank).
src/main/resources it contains images/properties files (In above example, we need to create this structure manually).
Maven还创建了一个示例Java源文件和Java测试文件。打开C:MVNconsumerBankingsrcmainjavacomcompanynameank文件夹,会看到App.java。
package com.companyname.bank;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
打开 C:MVNconsumerBankingsrcestjavacomcompanynameank 文件夹, 会看到 AppTest.java.
package 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 );
}
}追问
按照步骤输入命令 报错信息如下
热心网友 时间:2023-06-27 10:38
首先要确定你的maven环境是否配置正确(在控制台命令里面输入 mvn 如果有输出则配置正确),
其次在cmd里面进入到一个你建立的目录,然后
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
变可以生成项目