在不同的线程与Maven执行Java的主要方法 [英] Execute Java main method on a different thread with Maven

查看:172
本文介绍了在不同的线程与Maven执行Java的主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是我的Ant项目转换为一个Maven项目。

I am converting my Ant project to a Maven project.

在蚂蚁,我调用Java类,但在不同的线程使用叉=YES在Ant中选择。

In Ant I am invoking a Java class but in a different thread using fork="yes" option in Ant.

现在我试图找到在Maven中相似的任务。

Now I am trying to find a similar task in Maven.

我有code像下面这样,但我不知道这是否是正确与否。这是叫我的主类如预期,但它是在同一个线程/ JVM上运行。

I have code like the following, but I'm not sure if it is correct or not. It is calling my main class as expected, but it is running in the same thread/JVM.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>com.App</mainClass>
        <arguments>
            <argument>-s src/main/resources</argument>
        </arguments>
    </configuration>
</plugin>

下面com.App是具有main方法的类。

Here com.App is a class which has a main method.

我需要在不同的线程运行这个,因为App.main()方法中包含 A调用System.exit(),因此控制不回来了。由于我无权更改App类,我不得不调用在不同的线程。

I need to run this in a different thread because the App.main() method contains a call to system.exit(), so the control is not coming back. As I am not authorized to change the App class, I have to call that in a different thread.

推荐答案

只是使用而不是Java的目标EXEC目标,并使用JAVA_HOME /斌/ Java作为可执行文件。这应该做;)

just use the exec goal instead of the java goal and use JAVA_HOME/bin/java as the executable. This should do ;)

这篇关于在不同的线程与Maven执行Java的主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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