无法创建新的maven hello-world项目

Lon*_*guy 58 java maven

我正在看几个maven教程视频,然后我在安装maven后遇到了这个命令:

mvn archetype:create -DgroupId=com.di.maven -DartifactId=hello-world
Run Code Online (Sandbox Code Playgroud)

构建失败并引发以下错误:

Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.3:create 
(default-cli) on project standalone-pom: Unable to parse configuration of mojo 
org.apache.maven.plugins:maven-archetype-plugin:2.3:create for parameter #: Abstract 
class or interface 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be 
instantiated -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

是什么原因,我该如何解决?我在Ubuntu中以用户身份运行.

Ahm*_*aya 165

改变creategenerate

mvn archetype:generate -DgroupId=com.di.maven -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Run Code Online (Sandbox Code Playgroud)

  • 你可以解释为什么这有效而不是创造? (23认同)
  • mvn archetype:在Maven 3.0.5及更高版本中不推荐使用create (3认同)

小智 71

mvn archetype:create如文档中所述,在Maven 3.0.5及更高版本中已弃用

mvn archetype:generate改为使用:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-archetype

这是一个交互式命令,并会要求像价值观groupId,artifactId,version等你也可以在命令中指定这些值,并选择非交互模式.


小智 7

mvn archetype:generate 
  -DgroupId=com.biswajit.maven 
  -DartifactId=com.biswajit.maven 
  -DarchetypeArtifactId=maven-archetype-quickstart 
  -DinteractiveMode=false
Run Code Online (Sandbox Code Playgroud)

创建在maven 3.0.X或更高版本中不起作用.所以使用generate而不是create