我目前正在做一个项目,该项目使用一个工具,该工具采用以下示例IDL文件,并从该文件生成大约5个Java类。
struct Example { int x; int y; };
有没有办法让Maven在构建时使用命令行工具自动创建这些Java类?
发布于 2012-01-11 00:53:32
你可以使用maven-antrun-plugin插件来运行任意的Ant tasks,甚至任何命令行程序:
<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>使用这种配置,您的命令行程序将在编译之前执行,因此生成的Java源代码将可用于其余代码。
发布于 2012-01-11 00:35:54
下面是一个使用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>https://stackoverflow.com/questions/8806795
复制相似问题