2

我正在尝试遵循 maven 的入门手册,但我收到此错误

c:\Ambiente\workspace>mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archety
pes \ -DgroupId=com.mycompany.app \  -DartifactId=my-app -X
Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-27 23:15:32-0300)
Maven home: C:\Ambiente\apache-maven-3.1.0
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: pt_BR, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from C:\Ambiente\apache-maven-3.1.0\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\t316360\.m2\settings.xml
[DEBUG] Using local repository at C:\Users\t316360\.m2\repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\t3163
60\.m2\repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent
: null]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.078s
[INFO] Finished at: Mon Jul 22 17:23:03 BRT 2013
[INFO] Final Memory: 11M/247M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this d
irectory (c:\Ambiente\workspace). Please verify you invoked Maven from the correct directo
ry. -> [Help 1]
org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a proj
ect to execute but there is no POM in this directory (c:\Ambiente\workspace). Please verif
y you invoked Maven from the correct directory.

什么是 POM,我应该怎么做才能拥有这个文件?

4

3 回答 3

3

pom.xml 文件描述了如何构建项目。它可以被认为是 C/C++ 中 Makefile 或 Python 中 setup.py 的 Java 版本。您是否在遵循特定示例?

于 2013-07-22T20:28:39.680 回答
2

pom.xml文件是 Maven 中项目配置的核心。它是一个单一的配置文件,其中包含以您想要的方式构建项目所需的大部分信息。POM 非常庞大,其复杂性令人望而生畏,但无需了解所有复杂性即可有效地使用它。

下面只是一个简单的example

<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>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

要构建您在pom.xml文件中指定的依赖项,请执行: mvn clean package 成功后,mvn package您将看到如下内容:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jul 23 (Time..)
[INFO] Final Memory: 3M/6M
[INFO] -----------------------------

上面的命令会将所有依赖项下载到您的主目录/home/user/.m2/..

  1. 看看这个如何创建一个 Maven 项目
  2. 在 5 分钟内查看Maven
于 2013-07-22T20:37:13.773 回答
0

您尝试该命令的方式应该适用于 Linux 环境并且您正在运行 Windows。请仔细检查命令(可能删除 \ ),它应该可以正常工作。

于 2016-06-25T14:19:02.773 回答