Maven 学习笔记 045 创建 Java Module
1. 创建 java 工程模块
父工程的 pom.xml 会自动出现 modules,打包方式自动改成 pom
<?xml version="1.0" encoding="UTF-8"?>
<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.atguigu.maven</groupId>
<artifactId>pro01-maven-idea-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>pro02-module-java</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
2. 测试
pro02-module-java 增加 junit 依赖,添加完后手动导入一下,否则不能用
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
增加类
package com.atguigu.maven;
public class Hello {
public void showMessage() {
System.out.println("每一个不曾起舞的日子,都是对生命的辜负。");
}
}
package com.atguigu.maven;
import org.junit.Test;
public class HelloTest {
@Test
public void testShowMessage() {
new Hello().showMessage();
}
}