Is there a way to execute a program in maven to create your project?

I am currently working on a project that uses a tool that takes the following example IDL file and generates about 5 Java classes from it.

struct Example { int x; int y; };

Is there a way to force Maven to use the command line tool that we use to automatically create these Java classes when it is created?

+4
source share
2 answers

You can use the maven-antrun-plugin plugin to run an arbitrary Ant task or even any program from the command line:

 <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <configuration> <tasks> <exec executable="ls"> <arg value="-l"/> <arg value="-a"/> </exec> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

In this configuration, your command line program will run before compilation, so the generated Java sources will be available to the rest of the code.

+1
source

Here is an example using Exec Maven Plugin .

 <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <!-- this execution happens just after compiling the java classes, and builds the native code. --> <id>build-native</id> <phase>process-classes</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>src/main/c/Makefile</executable> <workingDirectory>src/main/c</workingDirectory> </configuration> </execution> </executions> </plugin> </plugins> 
+7
source

Source: https://habr.com/ru/post/1390274/


All Articles