我使用maven调用程序(而不是调用程序插件)在Java应用程序中运行mvn archetype:generate
。并且远程原型具有一些<description>海大物联微服务<description>
之类的汉字,它们在创建本地项目后无法正确显示。我发现platform encoding
是US-ASCII
,这是问题吗?我可以将此值设置为UTF-8
吗?
我尝试使用System.setProperty("project.build.sourceEncoding","UTF-8");
,但不起作用。
这是我的代码
public class Generator {
public static void main(String[] args) {
System.setProperty("maven.home","/usr/local/Cellar/maven/3.6.0/libexec");
System.setProperty("project.build.sourceEncoding","UTF-8");
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(Collections.singletonList("archetype:generate"));
request.setBatchMode(Boolean.TRUE);
request.setDebug(Boolean.TRUE);
Path path = Paths.get("/Users/eric/Documents/Tmp/");
request.setBaseDirectory(path.toFile());
Properties properties = new Properties();
properties.setProperty("groupId", "com.maven");
properties.setProperty("artifactId", "test");
properties.setProperty("archetypeVersion", "1.1");
properties.setProperty("archetypeGroupId", "org.apache.maven.archetypes");
properties.setProperty("archetypeArtifactId", "maven-archetype-quickstart");
properties.setProperty("archetypeCatalog", "remote");
request.setProperties(properties);
Invoker invoker = new DefaultInvoker();
try {
InvocationResult result = invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
}
}
这是日志
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 1.8.0_202, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: US-ASCII
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"