本来swf的编译使用maven+flexmojos,但是flexmojos一直没有新版本,适应不了新的flex sdk,只好换ant了,也很简单,贴脚本。
主build.xml文件
<?xml version="1.0"?> <project name="sangame-client" default="build"> <property environment="SystemVariable" /> <!-- Define variables/paths used in this build script --> <!-- Depending on the host os, fetch relevant prop file --> <condition property="platformSpecificPropertyFile" value="build.mac.properties"> <os family="mac" /> </condition> <condition property="platformSpecificPropertyFile" value="build.win.properties"> <os family="windows" /> </condition> <condition property="platformSpecificPropertyFile" value="build.unix.properties"> <os family="unix" /> </condition> <property file="${platformSpecificPropertyFile}" /> <property file="./build.properties" /> <!-- Have you edit the properties file to make sure the paths are right on your system? --> <target name="properties"> <fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail> <fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail> <fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail> </target> <!-- Extension for ANT to allow for tasks like "for" and "propertyregex" --> <!-- <taskdef resource="net/sf/antcontrib/antlib.xml"> <classpath> <pathelement location="${setup.lib}/ant-contrib-1.0b3.jar" /> </classpath> </taskdef> --> <!-- Cleans project --> <target name="clean"> <delete dir="${build}" /> <delete dir="${dist}" /> </target> <!-- creates buid/dist folders --> <target name="init"> <mkdir dir="${build}" /> </target> <!-- Compile all of the classes under the "src" tree into a .swf file --> <target name="build" depends="init"> <exec executable="${mxmlc.exe}" dir="${basedir}/sangame" failonerror="true"> <arg line="src/Sangame.as" /> <arg line="-target-player 11.4" /> <arg line="-use-network=true" /> <arg line="-source-path 'src' " /> <arg line="-library-path '${m2.repo}/com/baolemon/sangame/client/gear-framework/1.0.3-SNAPSHOT/gear-framework-1.0.3-SNAPSHOT.swc' " /> <arg line="-o ${build}/sangame-client.swf" /> <arg line="-load-config ${flexsdk.dir}/frameworks/flex-config.xml" /> <arg line="-warn-no-constructor=false" /> </exec> </target> </project>
build.properties
# -----------------------------------------------------------------
# Build script variables.
#
# You shouldn't have to change anything in here, look for
# build.win.properties and build.mac.properties for environment
# specific variables.
# -----------------------------------------------------------------
# release folders
dist = dist
#dist.examples = ${dist}/examples
#dist.docs = ${dist}/docs
# temp build folders
build = ./build
build.config = ${build}/config
# build config folders
#setup = ./setup
#setup.config = ${setup}/config
#setup.lib = ${setup}/lib
# The path to the flexunit.swc -- Required when trying to build/run unit
# tests for this library.
flexunit.swc = ${setup.lib}/flexunit.swc
# various flex paths, derived from flex home in your machine specific properties
# set os specific flex.home in setup/config/build.os.properties
# flexsdk.dir = ${flex.home}/sdks/${flex.version}
flexsdk.dir = ${flex.home}
#flexsdk.dir = D:/Downloads/flex_sdk_4.6.2
flexsdk.lib = ${flexsdk.dir}/frameworks
flexsdk.templates.dir = ${flexsdk.dir}/asdoc/templates
asdoc.exe = ${flexsdk.dir}/bin/${asdoc.exe.name}
mxmlc.exe = ${flexsdk.dir}/bin/${mxmlc.exe.name}
compc.exe = ${flexsdk.dir}/bin/${compc.exe.name}
# -----------------------------------------------------------------
# File Names - DO NOT MODIFY
# -----------------------------------------------------------------
testRunner.dir = .
testRunner.name = FlexLibTestRunner
# built library name
#library.name = flexlib
# -----------------------------------------------------------------
# Project Paths - DO NOT MODIFY
# -----------------------------------------------------------------
#examples.dir = ${basedir}/examples
#src.dir = ${basedir}/src
#tests.dir = ${basedir}/tests
为了适应不同的操作系统编译(开发在windows上,build服务器在linux上),使用对应不同操作系统的配置文件。
build.win.properties
# The location of the Flex SDK on your system.
# flex4
# flex.home = C:/Program Files/Adobe/Flash Builder 4 Plug-in
# flex.version = 4.0.0
# flex 3
#flex.home = D:/Downloads/flex_sdk_4.6.2
flex.home = ${SystemVariable.FLEXSDK_HOME}
m2.repo = ${SystemVariable.USERPROFILE}/.m2/repository
flex.version = 4.6.2
# conditional compilation variables, whether you're building against flex 3 or 4
# note: both variables must be set, both are actually used in the code base. They
# obviously should be set to opposite values :)
flex.version3 = true
flex.version4 = false
# name for the Flex compiler binaries. The path will be derived from the flex home + version.
asdoc.exe.name = asdoc.exe
mxmlc.exe.name = mxmlc.exe
compc.exe.name = compc.exe
# path to flash debug player binary
# The debug player is necessary here because it writes trace statements to a flashlog.txt
# file. This allows us to examine the .txt file and determine the status of unit tests
# in an automated fashion.
flashDebugPlayer.exe = ${flex.home}/Player/10/win/FlashPlayer.exe
# Location of the command-line SVN client.
svn.exe = /usr/local/bin/svn
build.unix.properties
# The location of the Flex SDK on your system.
flex.home = ${SystemVariable.FLEXSDK_HOME}
m2.repo = ${SystemVariable.HOME}/.m2/repository
flex.version = 4.6.2
# conditional compilation variables, whether you're building against flex 3 or 4
# note: both variables must be set, both are actually used in the code base. They
# obviously should be set to opposite values :)
flex.version3 = true
flex.version4 = false
# Name for the Flex compiler binaries. The path will be derived from the flex home + version.
asdoc.exe.name = asdoc
mxmlc.exe.name = mxmlc
compc.exe.name = compc
# path to flash debug player binary
flashDebugPlayer.exe = flashplayer
# Location of the command-line SVN client.
svn.exe = svn
build.mac.properties(该文件内容没有测试过)
# The location of the Flex SDK on your system.
# Flash builder's default flex4 sdk
# flex.home = /Applications/Adobe Flash Builder 4 Plug-in
# flex.version = 4.0.0
# Flash builder's default flex3 sdk
# flex.home = /Applications/Adobe Flash Builder 4 Plug-in
# flex.version = 3.4.1
# Flex builder's default flex3 sdk
flex.home = /Applications/Adobe Flex Builder 3 Plug-in
flex.version = 3.2.0
# conditional compilation variables, whether you're building against flex 3 or 4
# note: both variables must be set, both are actually used in the code base. They
# obviously should be set to opposite values :)
flex.version3 = true
flex.version4 = false
# name for the Flex compiler binaries. The path will be derived from the flex home + version.
asdoc.exe.name = asdoc
mxmlc.exe.name = mxmlc
compc.exe.name = compc
# The debug player is necessary here because it writes trace statements to a flashlog.txt
# file. This allows us to examine the .txt file and determine the status of unit tests
# in an automated fashion.
#due to OSX package concept, you can't just run Flash Player.app
flashDebugPlayer.exe = ${flex.home}/Player/mac/10/mac/Flash Player.app/Contents/MacOS/Flash Player
# Location of the command-line SVN client.
svn.exe = /usr/local/bin/svn
如果编译swc,则ant脚本为
<?xml version="1.0"?> <project name="gear" default="release"> <property environment="SystemVariable" /> <property file="./build.properties" /> <!-- Have you edit the properties file to make sure the paths are right on your system? --> <target name="properties"> <fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail> <fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail> <fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail> </target> <!-- Cleans project --> <target name="clean"> <delete dir="${build}" /> </target> <!-- creates buid/dist folders --> <target name="init"> <mkdir dir="${build}" /> </target> <!-- Compile all of the classes under the "src" tree into a .swc file --> <target name="lib" depends="init"> <exec executable="${compc.exe}" dir="${basedir}" failonerror="true"> <arg line="-target-player 11.4" /> <arg line="-compiler.source-path '${basedir}/src' " /> <arg line="-include-sources ${basedir}/src"/> <arg line="-o ${build}/gear.swc" /> <arg line="-load-config ${flexsdk.dir}/frameworks/flex-config.xml" /> </exec> </target> <target name="release" depends="clean"> <antcall target="lib" /> </target> <target name="release-sangame" depends="release"> <copy tofile="http://www.cnblogs.com/baolemon/sangame-client/gear/gear.swc" file="${build}/gear.swc" overwrite="true" /> </target> </project>