shell mvn archetype:generate -DgroupId=com.example -DartifactId=mylibrary -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false package com.example; public class Calculator { public int add(int a, int b) { return a + b; } } <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.example</groupId> <artifactId>mylibrary</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> </dependencies> </project> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> shell mvn clean install <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>mylibrary</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> package com.example; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class CalculatorTest { @Test public void testAdd() { Calculator calculator = new Calculator(); Assertions.assertEquals(5, calculator.add(2, 3)); } }


上一篇:
下一篇:
切换中文