经常使用vs code,不再想打开笨重的idea或者eclipse,直接使用maven测试一下代码,可以使用以下方法。首先使用命令:
mvn archetype:generate -DgroupId=com.ifixedbug -DartifactId=HelloWorld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
以上命令创建一个简单的项目。
紧接着pom.xml里加入需要的jar包。另外加入两个plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
一方面防止中文引起的字符问题,另一方便可以把第三方包打包在一起。最后使用命令:
mvn clean package
打包开始。接着使用:
java -cp target/HelloWorld-1.0-SNAPSHOT-jar-with-dependencies.jar com.ifixedbug.App