簡體   English   中英

安裝使用 mvn archetype:create-from-project 創建的多模塊原型時出錯

[英]Error installing a multimodule archetype created with mvn archetype:create-from-project

我有一個具有以下結構的項目:

項目 (pom)
項目客戶端(模塊,jar)
項目-ejb(模塊,jar)
項目網絡(模塊,戰爭)
項目耳(模塊,耳)

在 pom 中,模塊使用以下方法引用父級:

<relativePath>../project</relativePath>

並且根 pom 以相同的方式引用模塊(使用 ../)。

我可以使用 archetype:create-from-project 創建原型,並且一切運行順利。

但是當我嘗試安裝原型(mvn install 在目標/生成源/原型目錄中)時,我收到錯誤:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype:
    [ERROR] Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
    [ERROR] -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype: 
    Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        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:319)
        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:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        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.MojoExecutionException: 
    Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
        at org.apache.maven.archetype.mojos.IntegrationTestMojo.execute(IntegrationTestMojo.java:268)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more

問題是該文件存在(它在 target/generated-sources/archetype/src/main/resources/__rootArtifactId__client/pom.xml 上),我試圖擺弄 archetype-metadata.xml 沒有成功。 有什么線索嗎?

提前致謝

看起來原型插件不支持多模塊項目的平面布局。 如果是這種情況,解決方法是更改​​為嵌套布局。 我通過將 archetype-resources 目錄之外的模塊移到其中來做到這一點。 像這樣:

前:

pom.xml
src
├── main
│   └── resources
│       ├── archetype-resources
│       │   └── pom.xml
│       ├── META-INF
│       │   └── maven
│       │       └── archetype-metadata.xml
│       ├── __rootArtifactId__.module1
│       │   ├── pom.xml
│       │   └── ...
│       ├── __rootArtifactId__.module2
│       │   ├── pom.xml
│       │   └── ...
│       ├── __rootArtifactId__.module3
│           ├── pom.xml
│           └── ...
│
└── test
    └── resources
        └── projects...

后:

pom.xml
src
├── main
│   └── resources
│       ├── archetype-resources
│       │   ├── pom.xml
│       │   ├── __rootArtifactId__.module1
│       │   │   ├── pom.xml
│       │   │   └── ...
│       │   ├── __rootArtifactId__.module2
│       │   │   ├── pom.xml
│       │   │   └── ...
│       │   └── __rootArtifactId__.module3
│       │       ├── pom.xml
│       │       └── ...
│       └── META-INF
│           └── maven
│               └── archetype-metadata.xml
└── test
    └── resources
        └── projects...

然后編輯對 archetype-metadata.xml 中模塊的任何引用,刪除“..”相對路徑。

Maven Archetype JIRA 中也有類似的問題: https : //issues.apache.org/jira/browse/ARCHETYPE-422

在撰寫本文時,它仍然是開放的。

為了獲得我的項目的工作原型,我采用了 jboss-javaee6-webapp-ear-blank-archetype-7.1.3.CR1.jar 並使用它生成了一個項目。 由於我們使用的是 WebSphere,因此我修改了該項目以刪除許多特定於 jboss 的項目。 在這些修改之后,我從項目運行創建:

mvn clean archetype:create-from-project -Dinteractive=true

我修改了 archetype.groupId 和 archetype.artifactId 以設置我希望原型在存儲庫中結束的位置及其名稱。 我還修改了包值,但接受其他項目的默認值。

就像您所經歷的那樣,這似乎運行良好。 當我 cd 到 \\target\\generated-sources\\archetype 並運行 mvn install 時,會使用適當的路徑和名稱創建 jar 文件。

然后我使用 Eclipse 生成一個項目,這也很好用。 很棒,對吧?

因此,我針對我們的環境進行了一些小的更改,並使用相同的組和工件 ID 執行上述步驟。 然后我使用 Eclipse 生成一個項目,它給出了錯誤:

org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/pom.xml'

(我在 mvn archetype:generate 的命令行上並沒有一直收到相同的錯誤,但我已經看到它發生了。)

出於某種原因,從項目創建時,再次運行這些步驟並輸入不同的 archetype.artifactId 可以解決此問題。 當 m2e 不喜歡原型更新時,似乎有些東西會被破壞或改變。

無論如何,這可能值得一試。 我會看看我是否可以縮小問題的范圍,但現在我將為每個更新使用唯一的 artifactIds。

該問題似乎僅在使用 Eclipse m2e插件時出現。 我能夠使用以下命令行解決問題:

mvn archetype:generate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM