我是maven的新手,我想同时执行2个Java文件。我在StackOverflow上读了几篇文章,因为我对maven的了解有限,所以我不明白该怎么做。我在此处附加了pom.xml文件,并且在Mac终端中使用的命令行是:
mvn编译exec:java -Dexec.mainClass =“ org.parallel.ParseThread1”
我还有一个名为ParseThread2的文件,每次我分别运行它们时都是这样的:
mvn编译exec:java -Dexec.mainClass =“ org.parallel.ParseThread1”
mvn编译exec:java -Dexec.mainClass =“ org.parallel.ParseThread2”
我想知道maven是否能够同时执行两个任务。
我读到的几篇文章是:
How to execute multiple ant targets in maven
Executing multiple maven profiles
Maven Build multiple profiles in one go
我的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>
答案 0 :(得分:0)
请参阅此answer。
mvn compile
java -cp target/classes org.parallel.ParseThread1 &
java -cp target/classes org.parallel.ParseThread2 &