首页 > 解决方案 > Maven - 如何从原型创建项目

问题描述

我是 maven 的新手,我必须从原型 archetype-2jse-simple-1.1.1 创建项目,我在本地目录中有它。你能帮我在终端中使用什么控制台命令吗?我只知道我必须使用 mvn archetype:generate。我尝试了几次,但我不知道运行我的本地原型。

标签: javamavenmvn-repo

解决方案


在 maven 中使用时,archetype:generate您可以指定用于生成 maven 项目的原型。

mvn archetype:generate -DarchetypeGroupId=<archetype group id> -DarchetypeArtifactId=<archetype artifactid> -DarchetypeVersion=<archetype version>

例如,如果您的原型的 groupId 是cz.swigroup并且原型 artifactId 是archetype-2jse-simple并且版本是1.1.1那么命令将是。

mvn archetype:generate -DarchetypeGroupId=cz.swigroup -DarchetypeArtifactId=archetype-2jse-simple -DarchetypeVersion=1.1.1

更新

由于工件不是来自中央存储库,而是来自https://artifactory.cs.vsb.cz/libs-release-local/您必须在~/.m2/settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

    <profiles>
        <profile>
            <id>maven-repositories</id>
            <repositories>
                <repository>
                    <id>artifactory.cs.vsb.cz</id>
                    <name>artifactory.cs.vsb.cz</name>
                    <url>https://artifactory.cs.vsb.cz/libs-release-local/</url>
                </repository>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>maven-repositories</activeProfile>
    </activeProfiles>
</settings>

推荐阅读