我正在使用maven-exec-plugin来生成Thrift的java源代码。它调用外部Thrift编译器并使用-o指定输出目录"target/generated-sources/thrift“。
问题既不是maven-exec-plugin也不是Thrift编译器自动创建输出目录,我必须手动创建它。有没有一种好的/可移植的方法,在需要的时候创建缺失的目录?我不想在pom.xml中定义mkdir命令,因为我的项目需要独立于系统。
发布于 2010-11-03 18:49:36
不使用exec插件,而是使用antrun插件首先创建目录,然后调用thrift编译器。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources/thrift"/>
<exec executable="${thrift.executable}">
<arg value="--gen"/>
<arg value="java:beans"/>
<arg value="-o"/>
<arg value="target/generated-sources/thrift"/>
<arg value="src/main/resources/MyThriftMessages.thrift"/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>您可能还想看看maven-thrift-plugin。
发布于 2010-11-03 18:41:43
您可以定义一个ant任务来完成这项工作。将plugin声明放入项目的pom.xml中。这将使您的项目独立于系统:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>createThriftDir</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<delete dir="${thrift.dir}"/>
<mkdir dir="${thrift.dir}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>发布于 2016-11-18 18:20:11
如果你想在项目中的某个地方准备这样的文件夹结构,然后复制到你想要的地方,可以使用maven-resource插件来完成:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-folder</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<filtering>false</filtering>
<directory>${project.basedir}/src/main/resources/folders</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>https://stackoverflow.com/questions/4085973
复制相似问题