简体   繁体   English

用于用maven-antrun-plugin替换exec-maven-plugin的脚本

[英]script used for replacing exec-maven-plugin with maven-antrun-plugin

Many apologies if this ends up being a foolish question I'm a little out of my depth at the moment... 如果这最终成为一个愚蠢的问题,我深表歉意。

This is related to a previous question 这与先前的问题有关

Upgrading exec-maven-plugin from 1.1.1 to 1.2 or 1.3.2 将exec-maven-plugin从1.1.1升级到1.2或1.3.2

Essentially I have a maven java app which is being run from the command line in Jenkins (or command window to test). 本质上,我有一个Maven Java应用程序,该应用程序是通过Jenkins中的命令行运行的(或要测试的命令窗口)。 It runs some processing which takes an hour or so on the main server (2 days on a lesser machine!). 它在主服务器上运行需要一个小时左右的处理(在较小的计算机上需要2天!)。 It has been running with exec-maven-plugin 1.1.1. 它已经与exec-maven-plugin 1.1.1一起运行。 I recently updated some dependencies and oddly it now hangs at the end of processing where it didn't before. 我最近更新了一些依赖关系,奇怪的是,它现在挂在处理的末尾,而以前没有。 I googled a little and while I don't completely understand why this this seems to be a known issue. 我在Google上搜索了一下,虽然我不完全理解为什么这似乎是一个已知问题。 I tried to upgrade the exec-maven-plugin to 1.3.2 and this is failing which is what the above question was about. 我试图将exec-maven-plugin升级到1.3.2,但是失败了,这就是上面的问题。 In reality I think I got side tracked and I think I need to find a different way to run the code (?). 实际上,我想我已经被跟踪了,我认为我需要找到一种不同的方式来运行代码(?)。 Bringing me to the main thrust of the question... 把我带到这个问题的重点...

The answer I have seen most often (I am working in a Windows environment) and someone commented about is to replace exec-maven-plugin with maven-antrun-plugin. 我最常看到的答案(我在Windows环境中工作),有人评论说要用maven-antrun-plugin替换exec-maven-plugin。 Oddly though the main examples I've found on the internet don't really show how to do much more than run an echo command. 奇怪的是,尽管我在互联网上找到的主要示例并没有真正显示出除运行echo命令外还可以做更多的事情。 If I understand correctly I need to run the Ant exec command to run the code from the Main proc, and possible run another script to stop the main thread on completion (I'm even less clear about this actually). 如果我正确理解,我需要运行Ant exec命令从Main proc运行代码,并可能运行另一个脚本以在完成时停止主线程(实际上我对此不太清楚)。 I just can't get a handle on what I should be doing in the script. 我只是无法理解脚本中应该做什么。 Should I be looking at Ant documentation to work out how to build a build.xml file (I'm assuming not as it is a maven app and this seems like a backward step) or should I be running some dos commands to perform some tasks or some in built ant commands ? 我应该查看Ant文档以了解如何构建build.xml文件(我假设不是因为它是Maven应用,这似乎是一个后退的步骤),还是应该运行一些dos命令来执行一些任务?或一些内置的ant命令?

Just to re-iterate I'm not expecting anyone to write the script for me (!) but at the moment I just don't really understand what I am trying to achieve in the script, what level of commands I should be putting in it or how to begin. 只是重申一下,我不希望有人为我编写脚本(!),但此刻我只是不太了解自己要在脚本中实现什么,应该输入什么级别的命令?它或如何开始。 If anyone could point me in the right direction or show me up by pointing to some clear documentation somewhere I would be very grateful. 如果有人能指出正确的方向或通过指向某些地方的清晰文档向我展示,我将不胜感激。

In case I haven't been clear I have been running the application using 如果我不清楚,我一直在使用

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>    
<executions>
    <execution>
        <phase>install</phase>
        <goals>
            <goal>java</goal>
        </goals>
        <configuration>
            <mainClass>com.org.dc.dcClient</mainClass>
        </configuration>
</execution>

I think the solution to my issue (Maven not getting control back on code competion) is to alter this to something along the lines of 我认为解决我的问题(Maven无法重新控制代码竞争)的方法是将其更改为类似于

<build>
  <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
        <executions>
           <execution>
              <phase>install</phase>
              <goals>
                 <goal>run</goal>
              </goals>
              <configuration>
              <tasks>
                 <echo>Using Ant Run</echo>
                 <exec [script]"/>
              </tasks>                  
              </configuration>
           </execution>
        </executions>

Thanks 谢谢

If all you need is execute a java class then adding following lines to your pom will do the job. 如果您只需要执行一个Java类,则将以下行添加到pom中即可完成工作。

    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
      <execution>
        <phase> <!-- a lifecycle phase --> </phase>
        <configuration>
          <target>
            <java classname="test.Main">
             <arg value="-h"/>
             <classpath>
               <pathelement location="dist/test.jar"/>
               <pathelement path="${java.class.path}"/>
             </classpath>
           </java>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>

Note the part between target tags. 注意目标标签之间的部分。 You need to deal with the configuration for classpath etc. 您需要处理classpath等的配置。

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

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