flexmojos : 无法复制 srcmainresources 文件问题的解决方法

    技术2026-08-08  6

    运行环境:

    flex sdk4 , maven3.0, flexmojos 3.8,

     

    问题描述:

    flexmojos 在进行 compile-swf 时,无法将 src/main/resources 下的文件同步到 outputDirectory,这将会造成编译后的 swf 无法正常读取到原先定义在 src/main/resources 内的各种文件(jpg,css...)。

    可能是 flexmojos 还不太够完美,configuration 中的所有参数都尝试了,问题仍无法解决。

     

    解决思路:

    通过 maven-antrun-plugin 来自定义一个phase同步到 ant target,转而由 ant 复制 src/main/resources 文件到 outputDirectory。

     

    具体步骤:

    1、在 flex 项目 pom.xml 中添加 maven-antrun-plugin:

    <project> <dependencies...> <build> ... <plugins> <!--flexmojos 插件--> <plugin...> <!--maven-antrun-plugin--> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>run</id> <!--定义一个比较快的 phase--> <phase>validate</phase> <configuration> <target> <!--将 maven 中设置的参数传給 ant--> <property name="client_deploy_path" value="${client.deploy.path}"/> <!--外部的 ant build.xml文件--> <ant antfile="${project.basedir}/ant-build.xml"/> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>

    说明:

    1)定义在 mvn validate 时进行 ant build,可以根据需要设置为其他 compile, install.. 我这里设置 validate 只是时间少一点 :)

    2)保持 pom.xml 的整洁,设置读取外部的 ant build.xml文件

    3)pom.xml 其他配置见 这里。

     

    2. 建立ant build.xml

    在 pom.xml 定义的 antfile 路径下,建立ant-build.xml

    <?xml version="1.0" encoding="UTF-8" ?> <project name="maven-antrun-" default="copyResources" > <target name="copyResources"> <echo message="copying file(s) to : ${client_deploy_path}..."/> <!--需要拷贝的文件目录--> <property name="resourceFolder" value="${basedir}/src/main/resources"/> <!--目标文件夹--> <property name="destinationFolder" value="${client_deploy_path}"/> <!--先删除原来文件--> <delete dir="${destinationFolder}/assets" /> <!--拷贝文件--> <copy todir="${destinationFolder}" overwrite="true" failοnerrοr="true"> <fileset dir="${resourceFolder}"/> </copy> </target> </project>

     

    3.运行脚本

    输入mvn validate flexmojos:compile-swf,即可进行compile-swf 的同时将 src/main/resources 下的文件拷贝到定义的目录下。

     

    最新回复(0)