我试图建立一个项目。它失败了。我做了正确的更改并尝试再次构建它。我解除了以下错误:
Embedded error: Directory simple already exists - please run from a clean directory
dan@dan-netbook:~/Documents/Maven/mavenbook-examples-1-SNAPSHOT/ch03-simple$ mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook -e
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] Chapter 3 Parent Project
[INFO] Chapter 3 Simple Project Example
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Chapter 3 Parent Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [archetype:create {execution: default-cli}]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.sonatype.mavenbook.ch03
[INFO] Parameter: packageName, Value: org.sonatype.mavenbook
[INFO] Parameter: package, Value: org.sonatype.mavenbook
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: basedir, Value: /home/dan/Documents/Maven/mavenbook-examples-1-SNAPSHOT/ch03-simple
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error creating from archetype
Embedded error: Directory simple already exists - please run from a clean directory
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error creating from archetype
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating from archetype
at org.apache.maven.archetype.mojos.MavenArchetypeMojo.execute(MavenArchetypeMojo.java:243)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Directory simple already exists - please run from a clean directory
at org.apache.maven.archetype.old.DefaultOldArchetype.createArchetype(DefaultOldArchetype.java:251)
at org.apache.maven.archetype.old.DefaultOldArchetype.createArchetype(DefaultOldArchetype.java:117)
at org.apache.maven.archetype.mojos.MavenArchetypeMojo.execute(MavenArchetypeMojo.java:227)
... 19 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Sun Dec 12 18:53:08 EST 2010
[INFO] Final Memory: 10M/26M
[INFO] ------------------------------------------------------------------------
这让我相信我需要清理目录或其他东西。我打电话给mvn clean
,但这不能解决问题。我确定这是一个非常基本的问题,但我只是在学习。有什么建议吗?
父:
<pre>
<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>
<artifactId>examples</artifactId>
<groupId>org.sonatype.mavenbook</groupId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven: The Definitive Guide Example Code</name>
<description>Example Code for Maven: The Definitive Guide</description>
<url>http://sonatype.com/book</url>
<modules>
<module>ch03-simple</module>
<module>ch04-custom</module>
<module>ch05-simple-web</module>
<module>ch06-multi</module>
<module>ch07-multi-spring</module>
<module>ch08-optimize</module>
<module>ch09-pom</module>
<module>ch10-lifecycle</module>
<module>ch11-profile</module>
<module>ch12-assembly</module>
<module>ch13-properties</module>
<module>ch15-sitegen</module>
<module>ch17-writing-plugins</module>
<module>ch18-alternate-plugins</module>
</modules>
<build>
<finalName>mavenbook-examples-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>examples</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>publish</id>
<distributionManagement>
<site>
<id>sonatype-site</id>
<name>Sonatype Book Examples</name>
<url>file:///var/www/domains/sonatype.com/www/htdocs/book/book-examples/</url>
</site>
</distributionManagement>
<properties>
<sonatype.site>file:///var/www/domains/sonatype.com/www/htdocs/</sonatype.site>
</properties>
</profile>
<profile>
<id>stage</id>
<distributionManagement>
<site>
<id>sonatype-site</id>
<name>Sonatype Book Examples</name>
<url>file:///var/www/domains/sonatype.com/www/htdocs/book-stage/book-examples/</url>
</site>
</distributionManagement>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</reporting>
<repositories>
<repository>
<id>sonatype-forge</id>
<name>Sonatype Forge</name>
<url>http://repository.sonatype.org/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>Central</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
</pre>
其他Pom
<pre>
<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>
<parent>
<groupId>org.sonatype.mavenbook</groupId>
<artifactId>examples</artifactId>
<version>1-SNAPSHOT</version>
</parent>
<groupId>org.sonatype.mavenbook.ch03</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<name>Chapter 3 Parent Project</name>
<url>http://sonatype.com/book</url>
<modules>
<module>simple</module>
</modules>
</project>
</pre>
由于
答案 0 :(得分:3)
以防万一其他人遇到这个问题......我遇到了同样的问题(刚刚学习maven),这对我有用:
如果您下载了代码,请不要运行示例章节目录中的命令,例如/家庭/ uruser /行家/ mavenbook-例子-1-快照/ CH03-简单
只需设置一个像/ home / uruser / maven / myTestChapterThree这样的新目录,然后运行以下命令:
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook -e
新手的东西可以肯定,但至少three maven新手(包括我自己)已经打到了这堵墙,所以可能是book下载示例章节的建议然后运行可能是问题的命令:)
答案 1 :(得分:0)
在您的应用程序中,我对ArtifactId
感到困惑,因为我将您的论点作为"example"
传递给"simple"
。以下是创建新工件的简单示例。
<强> 1。为原型工件
创建一个新项目和pom.xml原型工件的示例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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.groupId</groupId>
<artifactId>my-archetype-id</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
您需要指定的只是groupId,artifactId和version。稍后将通过archetype:create from the commandline调用原型来使用这三个参数。
<强> 2。创建原型描述符
原型描述符是一个名为archetype.xml的文件,它必须位于src / main / resources / META-INF / maven /目录中。可以在快速入门原型中找到原型描述符的示例:
<archetype
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org
/plugins/maven-archetype-plugin/archetype/1.0.0
http://maven.apache.org/xsd/archetype-1.0.0.xsd">
<id>quickstart</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>
标记应与原型pom.xml中的artifactId相同。
可选的true标记可以运行原型:甚至可以在现有项目上创建。
,,,和标签代表项目的不同部分:
<sources> = src/main/java
<resources> = src/main/resources
<testSources> = src/test/java
<testResources> = src/test/resources
<siteResources> = src/site
<sources> and <testSources> can contain <source>
elements that specify a source file.
并且可以包含指定资源文件的元素。
将其他资源(例如src / main / webapp目录中的资源)放在标记内。
此时,只能指定要创建的单个文件,而不能指定空目录。
因此,上面显示的quickstart原型定义了以下目录结构:
archetype
|-- pom.xml
`-- src
`-- main
`-- resources
|-- META-INF
| `-- maven
| `--archetype.xml
`-- archetype-resources
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java
第3。创建原型文件和原型pom.xml
要创建的原型的下一个组件是原型pom.xml。任何pom.xml都会这样做,只是不要忘记将artifactId和groupId设置为变量($ {artifactId} / $ {groupId})。调用archetype:create。
时,两个变量都将从命令行初始化原型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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>jar</packaging>
<name>A custom project</name>
<url>http://www.myorganization.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<强> 4。安装原型并运行原型插件
现在您已准备好安装原型:
mvn install
现在您已创建了一个原型,您可以使用以下命令在本地系统上尝试它。在此命令中,您需要指定有关要使用的原型的完整信息(其groupId,其artifactId,其版本)以及有关要创建的新项目的信息(artifactId和groupId)。不要忘记包含您的原型版本(如果您不包含该版本,您的原型创建可能会失败并显示版本:未找到RELEASE的消息)
mvn archetype:create \
-DarchetypeGroupId=<archetype-groupId> \
-DarchetypeArtifactId=<archetype-artifactId> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<my.groupid> \
-DartifactId=<my-artifactId>
一旦您对原型的状态感到满意,您就可以像任何其他工件一样部署(或提交给ibiblio),然后任何Maven用户都可以使用原型。
开始创建Archetype的其他方式
不要手动创建原型所需的目录结构,只需使用
即可mvn archetype:create
-DgroupId=[your project's group id]
-DartifactId=[your project's artifact id]
-DarchetypeArtifactId=maven-archetype-archetype
之后,您现在可以自定义archetype-resources目录和archetype.xml的内容,然后继续执行步骤#4(安装原型并运行原型插件)。