使用Maven运行多个类 [英] Run multiple classes using Maven

查看:231
本文介绍了使用Maven运行多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个类的程序包(每个类封装一个可执行程序,即一个main()方法),即:

I have a package with several classes (each one encapsulating an executable program, i.e. with a main() method), i.e.:

com.myorg.examples.classA
com.myorg.examples.classB
etc.

所有类都属于同一包(com.myorg.examples).

All the classes belong to the same package (com.myorg.examples).

我知道我可以使用maven运行此类的一个,例如:

I know I can use maven to run one of such classes, eg:

mvn exec:java -D"exec.mainClass"="com.myorg.examples.classA"

我也知道我可以配置exec-maven-plugin,以便使用较短的命令来执行相同的操作,例如:

I also know I can configure exec-maven-plugin in order to do the same using a shorter command, eg:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
    <execution>
      <goals>
        <goal>java</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <mainClass>com.myorg.examples.classA</mainClass>
  </configuration>
</plugin>

然后使用:

mvn exec:java

但是,我想知道是否有可能:

However, I wonder if it would be possible:

  1. 要使用exec-maven-plugin(或另一个)来配置多个执行并执行类似的操作

  1. To use the exec-maven-plugin (or antoher one) to configure the several executions and do something like this

mvn exec:classA       # or,
mvn exec:java classA 

因此运行了classA,但使用的语法比纯exec:java短.对于XML结构,似乎只能设置一个类,所以我不确定如何实现.

so classA is run, but using a shorter syntax than plain exec:java. Looking to the XML structure it seems only one class can be set, so I'm not sure how to achieve that.

依次执行所有类,例如:

mvn exec-all

以运行classA,下一个classB等.

我们将非常欢迎您提供有关这些主题的任何帮助或链接.谢谢!

Any help or link about these topics will be highly welcomed. Thanks!

编辑:问题的第二部分已分解为其他发布.

second part of the question has been spined off to this other post.

推荐答案

因此,您现在可以通过以下方式致电Maven:

So you can now call Maven via:

以下将执行其中id为default-cli:

The following will execute the one where id: default-cli:

mvn exec:java

以下将执行id为second-cli的那一个:

The following will execute the one where id: second-cli:

mvn exec:java@second-cli

以下将执行id为thirds-cli的那一个:

The following will execute the one where id: thirds-cli:

mvn exec:java@third-cli

问题是为什么在一个不同的包中但在一个Maven模块中有几个主类,这听起来对我来说有不同的模块(因为您已经有包).另一个问题是为什么您需要执行它们通过exec-maven-plugin吗?目的是什么?

The question is why you have several main classes in a different packages but within a single Maven module which sounds for me to have different modules (as you already have packages).. The other question is why do you need to execute them via exec-maven-plugin? What is the intention ?

这篇关于使用Maven运行多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆