Java 在 pom.xml 中指定目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19852950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:42:44  来源:igfitidea点击:

specifying goal in pom.xml

javaxmleclipsemaven

提问by Scientist

I am creating a new maven project with pom.xmlas below:-

我正在创建一个新的 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>

The problem which i am facing is that target war file is not getting generated. On eclipse console after i ran this pom.xmlwhat i found was goals missing in pom.xml.

我面临的问题是没有生成目标战争文件。在我运行这个之后,在 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] 

Please tell me how to specify goals in pom.xml.

请告诉我如何在pom.xml.

Also tell me how to create RESTLET project using maven as build tool.

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

Thanks & Regards,

感谢和问候,

回答by Wouter

You should always give an argument to your maven command. Normally this is one of the lifecycles. For example:

您应该始终为您的 Maven 命令提供一个参数。通常这是生命周期之一。例如:

mvn package

Package will create jars, wars, ears etc.

包将创建罐子、战争、耳朵等。

For more phases and their meaning, see: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

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

回答by Narendra Rabari

The error message which you specified is nothing but you are not specifying goal for maven build.

您指定的错误消息什么也没有,但您没有为 Maven 构建指定目标。

you can specify any goal in your run configuration for maven build like clear, compile, install, package.

您可以在 Maven 构建的运行配置中指定任何目标,例如清除、编译、安装、打包。

please following below step to resolve it.

请按照以下步骤解决。

  1. right click on your project.
  2. click 'Run as' and select 'Maven Build'
  3. edit Configuration window will open. write any goal but your problem specific write 'package' in Goal text box.
  4. click on 'Run'
  1. 右键单击您的项目。
  2. 单击“运行方式”并选择“Maven 构建”
  3. 编辑配置窗口将打开。在目标文本框中写下任何目标,但您的问题特定写“包”。
  4. 点击“运行”

回答by Vahap Gencdal

1.right click on your project.
2.click 'Run as' and select 'Maven Build'
3. edit Configuration window will open. write any goal but your problem specific write 'package' in Goal
4user settings: show your maven->directory->conf->settings.xml for example; C:\maven\conf\settings.xml

1 .右键单击您的项目。
2.单击“运行方式”并选择“Maven Build”
3。编辑配置窗口将打开。在目标
4用户设置中写入任何目标,但您的问题特定写入“包” :例如显示您的 maven->directory->conf->settings.xml;C:\maven\conf\settings.xml

回答by timy kurian

  1. Go to Terminal
  2. Do mvn clean install
  1. 前往终端
  2. mvn clean install

回答by joao cenoura

I've bumped into this question because I actually wanted to define a default goal in pom.xml. You can define a default goal under build:

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

<build>
    <defaultGoal>install</defaultGoal>
...
</build>

After that change, you can then simply run mvnwhich will do exactly the same as mvn install.

更改后,您可以简单地运行mvn,这将与mvn install.

Note: I don't favor this as a default approach. My use case was to define a profile that downloaded a previous version of that project from Artifactory and wanted to tie that profile to a given phase. For convenience, I can run mvn -Pdownload-jar -Dversion=0.0.9and don't need to specify a goal/phase there. I think it's reasonable to define a defaultGoalin a profile which has a very specific function for a particular phase.

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

回答by Sidharth Taneja

Add the goal like -

添加目标,如 -

 <build>
        <defaultGoal>install</defaultGoal>
        <!-- Source directory configuration -->
        <sourceDirectory>src</sourceDirectory>
</build>

This will solve the issue

这将解决问题

回答by silfrede

if you are using Eclipse Make sure that you JRE Library under BUILT PATH points to the JDK FOLDER rather that the jre, if you are using java 7 then you need to create a setting.xml, and set up the proxy to allow the request under .m2 folder; however if you used java 8 jdk you should be find.

如果您使用的是 Eclipse 确保您在 BUILT PATH 下的 JRE 库指向 JDK FOLDER 而不是 jre,如果您使用的是 java 7 那么您需要创建一个 setting.xml,并设置代理以允许下的请求.m2 文件夹;但是,如果您使用 java 8 jdk,您应该会找到。

回答by Sagar Tripathi

I am facing same Issue after run my build.

运行我的构建后,我面临同样的问题。

The error message tell us to specify your goal

错误消息告诉我们指定您的目标

Jenkins Issue related to goal for build

Jenkins 与构建目标相关的问题

So I specify the goal Ex:-test.

所以我指定了目标 Ex:-test。

Now It's running fine

现在运行良好

回答by Shaked dounel

I stumbled upon this exception, and found out that I forgot to add a Main.
Check out if you have public static void main(String[] args)correctly.

我偶然发现了这个异常,发现我忘记添加一个 Main。
检查您是否public static void main(String[] args)正确。

Good luck!

祝你好运!

回答by Sarvjeets

You need to set the path of maven under Global setting like MAVEN_HOME

你需要在像 MAVEN_HOME 这样的 Global 设置下设置 maven 的路径

/user/share/maven

/用户/共享/Maven

and make sure the workbench have permission of read, write and delete "777"

并确保工作台具有读、写和删除“777”的权限