赞
踩
src/main/java —— 存放项目的.java文件
src/main/resources —— 存放项目资源文件,如spring, mybatis配置文件
src/test/java —— 存放所有测试.java文件,如JUnit测试类
src/test/resources —— 测试资源文件
target —— 项目输出位置
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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.hello.maven</groupId>
- <artifactId>Hello</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>Hello</name>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.9</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
- </project>
在src/main/java/com/hello/maven目录下新建文件Hello.java
- package com.hello.maven;
- public class Hello {
- public String sayHello(String name){
- return "Hello "+name+"!";
- }
- }
在src/test/java/com/hello/maven目录下新建测试文件HelloTest.java
- package com.hello.maven;
- import org.junit.Test;
- import static junit.framework.Assert.*;
- public class HelloTest {
- @Test
- public void testHello(){
- Hello hello = new Hello();
- String results = hello.sayHello("maven");
- assertEquals("Hello maven!",results);
- }
- }
2.5.1打开cmd命令行,进入Hello项目根目录执行 mvn compile命令,查看根目录变化
2.5.2cmd 中继续录入mvn clean命令,然后再次查看根目录变化
2.5.3cmd 中录入 mvn clean compile命令, 查看根目录变化
2.5.4cmd 中录入 mvn clean test命令,查看根目录变化
2.5.5cmd 中录入 mvn clean package命令,查看根目录变化
2.5.6cmd 中录入 mvn clean install 查看仓库会把项目安装到仓库里
HelloFriend
——src
————main
——————java
——————resources
————test
——————java
——————resources
——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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>com.hello.maven</groupId>
- <artifactId>HelloFriend</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>HelloFriend</name>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.9</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>com.qcby.maven</groupId>
- <artifactId>Hello</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
- </project>
在src/main/java/com/hello/maven目录下新建文件HelloFriend.java
- package com.hello.maven;
-
- public class HelloFriend {
-
- public String sayHelloToFriend(String name){
-
- Hello hello = new Hello();
- String str = hello.sayHello(name)+" I am "+this.getMyName();
- System.out.println(str);
- return str;
- }
-
- public String getMyName(){
- return "John";
- }
-
- }
在src/test/java/com/hello/maven目录下新建测试文件HelloFriendTest.java
- package com.hello.maven;
-
- import static junit.framework.Assert.assertEquals;
-
- import org.junit.Test;
-
- public class HelloFriendTest {
- @Test
- public void tesHelloFriend(){
- HelloFriend helloFriend = new HelloFriend();
- String results = helloFriend.sayHelloToFriend("zhangsan");
- assertEquals("Hello zhangsan! I am John",results);
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。