在pom.xml中指定目标

Sci*_*ist 48 java xml eclipse maven

我正在创建一个新的maven项目,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>firstRestlet</groupId>
  <artifactId>restlet1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>restlet1</name>
  <url>http://maven.apache.org</url>
  <repositories>
<repository>
   <id>maven-restlet</id>
   <name>Public online Restlet repository</name>
   <url>http://maven.restlet.org</url>
</repository> 
</repositories>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

我面临的问题是目标war文件没有生成.在运行此操作后的eclipse控制台上,我pom.xml发现的是目标缺失pom.xml.

ECLIPSE CONSOLE MESSAGE:

No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR] 
Run Code Online (Sandbox Code Playgroud)

请告诉我如何指定目标pom.xml.

还告诉我如何使用maven作为构建工具创建RESTLET项目.

感谢和问候,

Nar*_*ari 68

您指定的错误消息只是您没有为maven构建指定目标.

您可以在运行配置中为maven构建指定任何目标,例如clear,compile,install,package.

请按照以下步骤解决.

  1. 右键单击您的项目.
  2. 点击"运行方式"并选择"Maven Build"
  3. 编辑配置窗口将打开.写任何目标,但你的问题特定在目标文本框中写'包'.
  4. 点击'运行'


joa*_*ura 17

我碰到了这个问题,因为我实际上想在pom.xml中定义一个默认目标.您可以在构建下定义默认目标:

<build>
    <defaultGoal>install</defaultGoal>
...
</build>
Run Code Online (Sandbox Code Playgroud)

在更改之后,您可以简单地运行mvn与完全相同的操作mvn install.

注意:我不赞成这种默认方法.我的用例是定义一个从Artifactory下载该项目的先前版本的配置文件,并希望将该配置文件绑定到给定的阶段.为方便起见,我可以运行mvn -Pdownload-jar -Dversion=0.0.9,不需要在那里指定目标/阶段.我认为defaultGoal在配置文件中定义一个特定阶段具有非常特定功能的配置文件是合理的.


Wou*_*ter 14

你应该总是给你的maven命令一个参数.通常这是生命周期之一.例如:

mvn package
Run Code Online (Sandbox Code Playgroud)

包装将创造罐子,战争,耳朵等.

有关更多阶段及其含义,请参阅:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html


小智 8

1.点击你的项目.
2.点击"Run as"并选择"Maven Build"
3.编辑配置窗口将打开.在目标
4用户设置中编写任何目标,但你的问题特定写'包' :例如,显示你的maven-> directory-> conf-> settings.xml; C:\行家\的conf \的settings.xml


小智 5

  1. 前往终端
  2. mvn clean install


小智 5

添加目标,例如 -

 <build>
        <defaultGoal>install</defaultGoal>
        <!-- Source directory configuration -->
        <sourceDirectory>src</sourceDirectory>
</build>
Run Code Online (Sandbox Code Playgroud)

这将解决问题