简体   繁体   中英

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

Essentially I have a maven java app which is being run from the command line in Jenkins (or command window to test). It runs some processing which takes an hour or so on the main server (2 days on a lesser machine!). It has been running with 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. I tried to upgrade the exec-maven-plugin to 1.3.2 and this is failing which is what the above question was about. 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. 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. 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). 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 ?

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

<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.

    <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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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