可以说纠结了不少时间了
用mvn archetyoe:generate 时总是会出现以下的情况:
正常的应该是
Java代码
$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate]
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
...........
internal -> maven-archetype-sar (JBoss Service Archive)
36: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36): 15
....
以前使用一直正常(有一段时间了)
可现在无论在哪台机器上都是这样的情况:
Java代码
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> docbkx-quickstart-archetype (null)
2: remote -> gquery-archetype (null)
.......
288: remote -> trails-secure-archetype (null)
289: remote -> tynamo-archetype (null)
290: remote -> wicket-scala-archetype (Basic setup for a project that combines Scala and Wicket,
depending on the Wicket-Scala project. Includes an example Specs
test.)
291: remote -> circumflex-archetype (null)
Choose a number: 80:
....
居然是这样,到了290了....
而且choose a nubmer 默认写了个80不知道啥意思..... 选以前的web项目(18) 不管用还是继续让我choose version
最后发现可以choose的version 只有 1 和2 ..
根本没有普通java项目和web项目
咋回事儿?
后来找到了解决方案:
方案1:绕行
mvn archetype:create -DgroupId=[your group id] -DartifactId=[your archetype id] -DarchetypeArtifactId=maven-archetype-webapp
方案2 : 谢谢,juvenshun 大哥的帮助。(引用):
Java代码
可以使用 $mvn archetype:generate -DarchetypeCatalog=internal
archetypeCatalog表示插件使用的archetype元数据,默认值为remote,local,即中央仓库archetype元数据(http://repo1.maven.org/maven2/archetype-catalog.xml)加上插件内置元数据的和
由于中央仓库的archetype太多,导致这个列表太长
因此自己指定仅用内置元数据(20个左右,好像),就可以解决你的烦恼了
****************************************
maven自定义archetype
创建archetype
archetype:create -DgroupId=[package name] -DartifactId=[project name] -DarchetypeArtifactId=maven-archetype-archetype
创建archetype时DarchetypeArtifactId 必须填maven-archetype-archetype
在运行cmd输入
Java代码
mvn archetype:create -DgroupId=org.myArchetype -DartifactId=maven-my-archetype -DarchetypeArtifactId=maven-archetype-archetype
maven会在当前文件夹创建一个目录。
maven-my-archetype\src\main\resources\archetype-resources 目录下的文件会复制到新建的maven项目下面
maven-my-archetype\src\main\resources\META-INF\maven\archetype.xml
Xml代码
<archetype>
<id>maven-my-archetype</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>
这个文件是配置需要复制到新建项目下的文件,比如你的maven项目所在的包是org.test,maven会将src/main/java/App.java文件复制到src/test/java/org/test/App.java
安装到本地库
Java代码
maven-my-archetype>mvn install
创建maven项目
Java代码
mvn archetype:generate -DarchetypeGroupId=org.myArchetype -DarchetypeArtifactId=maven-my-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=org.test -DartifactId=test