在当前工作区中构建所有 Eclipse maven 项目的单个命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11797886/
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-09-19 18:45:13  来源:igfitidea点击:

Single command to build all Eclipse maven projects in current workspace?

javaeclipsemavenm2eclipsem2e

提问by JLund

Does anyone know any simple yet effective way to build all Maven projects in current workspace, for example, maven clean install for each such project.

有谁知道在当前工作区中构建所有 Maven 项目的任何简单而有效的方法,例如,为每个这样的项目进行 maven clean install。

Is it for example possible to select multiple projects and use something similar to ${project_loc} or get a popup with possible projects to use for the run configuration? Or any other way?

例如,是否可以选择多个项目并使用类似于 ${project_loc} 的内容或获取包含可能项目的弹出窗口以用于运行配置?还是有其他方式?

I'm using Eclipse Juno.

我正在使用 Eclipse Juno。

回答by davidfmatheson

Can you give them all a parent pom.xml and then mvn compilethe parent pom.xml?

你能给他们所有的父 pom.xml 然后mvn compile父 pom.xml 吗?

Look for project inheritance here.

在这里寻找项目继承。

If you can specify relative paths, this shouldn't be too hard. Create a new maven project with a pom.xml something like:

如果您可以指定相对路径,这应该不会太难。使用 pom.xml 创建一个新的 maven 项目,例如:

<?xml version="1.0"?>
<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>
    <groupId>com.example</groupId>
    <artifactId>parent-app</artifactId>
    <packaging>pom</packaging>
    <version>1</version>
    <modules>
        <module>../project1</module>
        <module>../project2</module>
    </modules>
</project>

Delete the projects from your Eclipse workspace (but not the file system) and then import the parent maven project. Now you can:

从 Eclipse 工作区(但不是文件系统)中删除项目,然后导入父 maven 项目。现在你可以:

Run As...> Maven build> clean compile(as Goals)

Run As...> Maven build> clean compile(作为目标)

and it should clean and compile all the projects.

它应该清理并编译所有项目。

回答by Bananeweizen

As a launch configuration is always related to one project, there is no way to put many projects into a launch configuration by pure Eclipse tooling. However, there are some workarounds:

由于一个启动配置总是与一个项目相关,所以没有办法通过纯 Eclipse 工具将多个项目放入一个启动配置中。但是,有一些解决方法:

  • Use a parent.pom to have a new project including all the existing ones (and doing the iteration in Maven).
  • Really define a launch config for each project and then use either CDTs launch groupsor the EclipseRunnerplugin to launch them batch like.
  • Use an Ant script to iterate over your workspace directories and call the launch config using Ant4Eclipse.
  • 使用 parent.pom 来创建一个新项目,包括所有现有项目(并在 Maven 中进行迭代)。
  • 真正为每个项目定义一个启动配置,然后使用CDT 启动组EclipseRunner插件来批量启动它们。
  • 使用 Ant 脚本遍历工作区目录并使用Ant4Eclipse调用启动配置。

That said, your best bet is the parent.pom, as it is a proven way and you can reuse that on your continuous integration server.

也就是说,最好的选择是 parent.pom,因为它是一种行之有效的方法,您可以在持续集成服务器上重用它。