开发者

Cannot create a maven project from my archetype

I'm developing projects in Eclipse and I'm using maven, so I've created a new archetype, using the 'maven-archetype-archetype' Archetype, but once I try to create a new project with the my new archetype, I get the following error message in Eclipse:

The META-INF/maven/archetype.xml descriptor cannot be found.

Any idea what could the reason be?

Update:

My archetype.xml file:

<archetype>
    <id>test-archetype</id>
    <sources>
        <source>src/</source>
    </sources>
    <testSources>
        <source>test/</source>
    </testSources>
</archetype>

My pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>$my.group.id</groupId>
    <artifactId>$test-archetype</artifactId>
    <version>$0.0.1</version>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

The folder structure is as described:

archetype
|-- pom.xml
`-- src
    `-- main
        `-- resources
            |-- META-INF
            |   `-- maven
            |       `--archetype.xml
            `-- archetype-resources
                |-- pom.xml
       开发者_运维技巧         `-- src
                `-- test    

Adam.


I had exactly the same problem where Eclipse would report that the archetype.xml could not be found even though it did exist in the correct location. I did finally get it working after restarting Eclipse. It seems that if the archetype project is installed/deployed in the same Eclipse session as where it is used to create a project that it error.


The problem is that you (or Eclipse) would appear to be using "mvn archetype:create" command to create the new project which has been deprecated.

You should instead be using "mvn archetype:generate"

See http://maven.apache.org/archetype/maven-archetype-plugin/plugin-info.html


If you are using Eclipse try to use Eclipse IAM, it has simple wizard and ready solution for maven, and good integration with eclipse.


This appears to be a bug relating to Maven Repositories within eclipse. Maybe it is fixed in newer versions of eclipse.

Here is a work around:

  1. When generating a new archetype, increment the archetype version (e.g. from 0.0.1-SNAPSHOT to 0.0.2-SNAPSHOT). After mvn install the new archetype version will appear in Workspace Projects, but not Local Repository.

  2. Rebuild Index on the Local Repository. The new archetype version will now appear in Local Repository and is available for use.


I've tried this again recently, now that I'm much more experienced with Maven, and the result was the same, there is an issue with making archetypes, as far as I can see, perhaps Eclipse bug, or miss configuration, but whatever I tried, it didn't do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜