首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在maven中根据需要创建目录

在maven中根据需要创建目录
EN

Stack Overflow用户
提问于 2010-11-03 18:16:41
回答 3查看 54.9K关注 0票数 44

我正在使用maven-exec-plugin来生成Thrift的java源代码。它调用外部Thrift编译器并使用-o指定输出目录"target/generated-sources/thrift“。

问题既不是maven-exec-plugin也不是Thrift编译器自动创建输出目录,我必须手动创建它。有没有一种好的/可移植的方法,在需要的时候创建缺失的目录?我不想在pom.xml中定义mkdir命令,因为我的项目需要独立于系统。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-03 18:49:36

不使用exec插件,而是使用antrun插件首先创建目录,然后调用thrift编译器。

代码语言:javascript
复制
<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

票数 37
EN

Stack Overflow用户

发布于 2010-11-03 18:41:43

您可以定义一个ant任务来完成这项工作。将plugin声明放入项目的pom.xml中。这将使您的项目独立于系统:

代码语言:javascript
复制
        <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>
票数 23
EN

Stack Overflow用户

发布于 2016-11-18 18:20:11

如果你想在项目中的某个地方准备这样的文件夹结构,然后复制到你想要的地方,可以使用maven-resource插件来完成:

代码语言:javascript
复制
<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>
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4085973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档