Compiling flex modules into swf with other mxml files in ant - apache-flex

I have a huge project with many mxml and as files and am trying to compile them all into one working swf file using ant. However, I'm having trouble compiling main.swf correctly in ant.
It doesn't seem to be pulling in the necessary modules, all of which are located in separate folders within the main src folder.
It will compile without error, but when I open the swf file, there is no content -- just a shell. However, if I compile using flex builder 3's compile button, it will create the swf correctly -- content and all.
Even when using a simple mxmlc command, it throws an error for any file associated with the modules saying there is an unknown type (meaning it's not pulling in the modules).
Is there a special way that modules should be dealt with when trying to compile them into a main.swf file using ant?

Did you include a library-path element in your Ant build file?
e.g.
<target ...>
<mxmlc output="...../file.swf"
....
file=".../main.mxml">
<library-path dir="..../" append="true">
<include name="...../someModule.swc"/>

Related

mxmlc embedding assets

I'm trying complie my project via mxmlc this way:
[prj_folder]\src>mxmlc mymxml.mxml -library-path+=../libs -sp+=..\assets
and i get such errors:
[prj_folder]\src\view\controls\controlname.mxml(7): Error: Problem finding external st
ylesheet: assets/cssname.css
<fx:Style source="assets/cssname.css"/>
[prj_folder]\src\view\constants\Images.as(24):
col: 3: Error: Unable to transcode
assets/ icons/icon1.png.
how to include assets for the compiler?
Flash Builder preprocesses the files.
For a directory structure like this:
projectdir/src/Main.mxml
projectdir/src/views/SomeView.mxml
projectdir/src/assets/MyImage.png
And if SomeView.mxml references assets/MyImage.png, Flash Builder will allow this:
#Embed('assets/MyImage.png')
because it is preprocessed to /assets/MyImage.png by the IDE, but ant/maven + mxmlc won't do that.
#Embed('/assets/MyImage.png')
works for both Flash Builder and mxmlc.
If you are using a relative path like this:
#Embed('../assets/MyImage.png')
try changing it to this, odd as it may seem:
#Embed('/../assets/MyImage.png')
The leading / gets translated to "my src directory", and mxmlc does the remainder of the path calculation from there.
Hope this helps.
This is a directory setup issue; not a compiler error. And you aren't actually embedding assets; just referencing them.
When using Flash Builder, the file "assets/cssname.css" should be relative to the main application file. I believe the same should occur if you're using the command line compiler.
Does your source directory have an assets subdirectory? Is the cssname.css file inside it?

AspNetCompiler including files that are not in my project

I'm using msbuild to automatically build and package a website ready for deployment. When I compile and then Publish my project through Visual Studio 2008 everything works fine.
However when I use msbuild I'm getting errors because AspNetCompiler is trying to compile aspx and ascx files that are not included in my .csproj, but still exist in version control.
I know I can just remove them from version control, but can anyone tell me why these files are being compiled?
Here is my msbuild task.
<AspNetCompiler
TargetPath="$(PackageDir)\Web"
VirtualPath="/"
PhysicalPath="$(buildDirectory)\Web"
Force="true"
/>
Thanks!
The AspNetCompiler task, which wraps _aspnet_compiler.exe_, compiles all "compilable" files in the application, rather than compiling only those files in the .csproj.
The giveaway is that none of the command-line parameters for the executable take a .csproj as input, only paths. (I suppose one could argue that it would look for a .csproj in the directory, but that is unlikely as it would introduce its own set of issues, such as what to do if someone had put two project files in one directory.)

use a style.css file from a .swc and build the Flex project with ANT

I have an .SWC library with a style.css file inside.
The .SWC file is added to my project and the style.css is used this way:
<fx:Style source="assets/style/style.css" />
If I want to build my project with an ANT-script it says that "the external stylesheet couldn't be found".
In ANT you need to write the path for assets with an leading "/". So this would work:
<fx:Style source="/assets/style/style.css" />
But in this case it isn't possible to retrieve the style.css from the .swc as the compiler says that "the external stylesheet couldn't be found".
Is there any way to use the style.css inside the .swc AND use ANT to build the project?
resolved:
problem was within the compiled SWC.
I've forgotten to say the ant file to add the style. When I checked the SWC, I checked the SWC compiled by the Flash Builder and not by the ant script.

Compiling MXML files into multiple SWF files using mxmlc compiler

I have a few mxml files that I want compiled into their respective SWF files using a configuration file. At the moment I can get 1 mxml file compiled into it's respective SWF file by using the file-spec attribute in the configuration file but how would I go about compiling multiple mxml files at once? Do I have a separate configuration file for each? I'm using MSBUILD and the mxmlc compiler.
This is how I specified the mxml file to be compiled:
<file-specs>
<path-element>..\somePath\myFile.mxml</path-element>
</file-specs>

How do I create a jar file, which includes xml and html files?

I am trying to create a jar file which includes some class and java files needed, but I also would like to include some extra xml, xsl, html, txt (README) files.
I am using Eclipse on Windows XP.
Is there an easy way for me to set up a directory structure and package all my files into a jar?
Add the files to a source folder and they can be included in the jar.
One common way is to have, at the root of your project, a src folder. Within that, folders for java files, and others. something like:
src/
css/
java/
html/
images/
Then you can make each of those subfolders a source folder (Right click, Use as Source Folder) and they should be available to add to the jar.
A .jar is nothing but a ZIP archive, so you can use any program capable of creating ZIPs. Just make sure that you include the manifest and all the class files.
I just added all the files into my Eclipse project (including the txt, html, xml, etc files).
Then I used Eclipse to File->Export->Jar File->Next
Check the "Export Java source files and resources" box.
Done.
If you're using Ant, you can use the jar task (see the examples section for how to include/exclude certain files, etc.)
If you move to an ANT (or Maven, for you Maven fans) then you can automate the Jar building very nicely, and also use it outside of Eclipse (e.g., in an automated build environment). All you need to do is copy the files from your src, jsp, foobar and resources locations into a build staging folder, then Jar the resulting files using ANT's Jar task.
<target name="makejar" depends="compile, copyfiles">
<jar destfile="${jars.dir}/myjarfile.jar" index="true" basedir="${build.dir}" />
</target>
One thing I look down on is including non-source (except package.html files for Javadoc) within the src folder. If you feel you have to do this to achieve something, then you are doing it wrong.

Resources