简体   繁体   English

如何使用命令行在 maven 中执行 2 个或多个 java 文件?

[英]How to execute 2 or multiple java file in maven using command line?

I am new in maven and I would like to execute 2 java file at the same time.我是 maven 新手,我想同时执行 2 个 java 文件。 I read a few posts in StackOverflow and because I do have limited knowledge with maven, I couldn't understand how to do it.我在 StackOverflow 上读了几篇文章,因为我对 maven 的知识有限,所以我不明白该怎么做。 I attached my pom.xml file here and the command line that I am using in mac terminal is:我在这里附上了我的 pom.xml 文件,我在 mac 终端中使用的命令行是:

mvn compile exec:java -Dexec.mainClass="org.parallel.ParseThread1" mvn 编译 exec:java -Dexec.mainClass="org.parallel.ParseThread1"

I have another file named: ParseThread2 and every time I am running them separately like this:我有另一个名为:ParseThread2 的文件,每次我像这样单独运行它们时:

mvn compile exec:java -Dexec.mainClass="org.parallel.ParseThread1" mvn 编译 exec:java -Dexec.mainClass="org.parallel.ParseThread1"

mvn compile exec:java -Dexec.mainClass="org.parallel.ParseThread2" mvn 编译 exec:java -Dexec.mainClass="org.parallel.ParseThread2"

I want to know if maven is capable of executing both at the same time.我想知道 maven 是否能够同时执行两者。

Few posts that i read was:我读过的几篇文章是:

How to execute multiple ant targets in maven 如何在 maven 中执行多个蚂蚁目标

Executing multiple maven profiles 执行多个 maven 配置文件

Maven Build multiple profiles in one go Maven 一次性构建多个配置文件

My pom.xml file is:我的 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.parallel</groupId>
  <artifactId>parallel</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>parallel</name>
  <url>http://maven.apache.org</url>

  <properties>
      <maven.compiler.source>1.9</maven.compiler.source>
      <maven.compiler.target>1.9</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>


  </dependencies>

</project>

See this answer .看到这个答案

mvn compile
java -cp target/classes org.parallel.ParseThread1 &
java -cp target/classes org.parallel.ParseThread2 &

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM