2

我正在尝试从现有的多模块 Maven 项目中创建一个原型。为此,我将目录更改为根目录(根 pom.xml 所在的位置)并发出“mvn archetype:create-from-project”。构建没有完成,我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project siaci-d: charsetName -> [Help 1]

使用 -e 和 -X 标志再次运行,我可以看到以下堆栈跟踪:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project siaci-d: charsetName
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoFailureException: charsetName
at org.apache.maven.archetype.mojos.CreateArchetypeFromProjectMojo.execute(CreateArchetypeFromProjectMojo.java:285)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more

我检查了 maven-archetype-plugin 文档,没有找到对 charsetName 属性的任何引用。所以,我对如何解决这个问题有点迷茫。我在 Ubuntu 机器上使用 maven 3.0.4 和 java 1.6.0_25。有什么建议吗?

知道这里出了什么问题吗?

4

2 回答 2

4

You posted this question some time ago, however this answer may help others.

I had the same problem in a project. This error happens when you have a file in your project that contains characters in a different encondig. A solution to this problem is replacing this characters — if it's not many, generate the archetype, revert the characters to the original and at last, change to the right enconding at the archetype metadata file.

Another option is to change the default enconding UTF-8 in the archetype generation, like this:

mvn archetype:create-from-project -Darchetype.properties=../archetype.properties 

For more information, follow this guides:

于 2012-08-23T13:01:03.983 回答
2

我正在处理同样的错误,然后我发现是什么弄乱了原型创建...首先,我通过在 pom.xml 上插入以下属性来选择编码 ISO-8859-1:

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
    <project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
    <project.resources.sourceEncoding>${project.build.sourceEncoding}</project.resources.sourceEncoding>
</properties>

之后,我在 pom.xml 的构建部分插入了带有以下所有配置的原型插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-archetype-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <defaultEncoding>${project.build.sourceEncoding}</defaultEncoding>
        <encoding>${project.build.sourceEncoding}</encoding>
        <archetypeArtifactId>archetype-wsjpa</archetypeArtifactId>
        <archetypeGroupId>br.com.example</archetypeGroupId>
        <archetypeVersion>1.0</archetypeVersion>
        <archetypeFilteredExtentions>java,xml</archetypeFilteredExtentions>
    </configuration>
</plugin>

通过这样做,您应该在自己的 pom.xml 中提供所有原型生成配置,而不是编写属性文件 (archetype.properties) 来声明此配置。

最后,我用mvn clean installthen运行 mavenmvn archetype:create-from-project -e -X

即便如此,您仍然可能会注意到一些编码错误,例如本文中报告的错误,即使您已更新 pom.xml,如上所示...如果您在为项目设置正确编码后仍然遇到相同的错误,尝试找出哪个项目文件仍然包含无效字符。要找到麻烦制造者文件,您应该观察 Maven 在控制台上显示的调试行,如下所示:"[DEBUG] InputFileName:src\main\resources\META-INF\persistence.xml"并检查哪些项目文件已写入文件夹${basedir}\target\generated-sources\archetype\src\main\resources\archetype-resources。在原型创建过程中发生编码错误时,上述文件夹与原始项目内容不匹配,这是因为 Maven 无法复制某些资源,因为属性指定的字符集中不包含无效或不兼容的字符。

于 2014-04-10T17:12:48.917 回答