首页 > 解决方案 > maven-archetype-plugin 因 ClassNotFoundException 而失败

问题描述

例如,我正在尝试运行 maven-archetype-plugin

mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.1:generate \
    -DarchetypeGroupId=org.apache.karaf.archetypes \
    -DarchetypeArtifactId=karaf-command-archetype \
    -DarchetypeVersion=4.2.6 \
    -DgroupId=examples.archetype \
    -DartifactId=my-test

但我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.1.1:generate 
  (default-cli) on project standalone-pom: Execution default-cli of goal
  org.apache.maven.plugins:maven-archetype-plugin:3.1.1:generate failed: 
  A required class was missing while executing 
  org.apache.maven.plugins:maven-archetype-plugin:3.1.1:generate: 
  org/apache/commons/lang/StringUtils

我尝试了多种原型(开源和专有),但结果总是上面的错误。以前的 maven-archetype-plugin 版本也会产生相同的错误。

我的环境是

您知道此问题的任何解决方案或解决方法吗(我已经尝试删除本地存储库文件夹)?

标签: mavenmaven-pluginapache-karaf

解决方案


我发现可行的解决方案是将 commons-lang 依赖项添加到 maven-archetype-plugin-3.1.2.pom

您可以在您的 maven 存储库 C:\Users\your_user\.m2\repository\org\apache\maven\plugins\maven-archetype-plugin\3.1.2\maven- 中找到 maven-archetype-plugin-3.1.2.pom原型插件3.1.2.pom

然后将 commons-lang 添加到依赖项中。

<dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.3</version>
</dependency>

希望能帮助到你。


推荐阅读