使用Maven构建Flex项目包括样式表 [英] Using Maven to build Flex project including stylesheets

查看:223
本文介绍了使用Maven构建Flex项目包括样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flex的样式表是由编译器解析,并捆绑了其资产(图形,通常情况下)成swf文件,然后可以在运行时加载。我有同款式的固定数量的一个项目(目前为4:老企业的风格,新的企业作风,以及两者的高对比度版本)。使用Flash Builder(Eclipse中使用Flex IDE插件)我能有编译成SWF文件旁边的主项目构件的.swf文件中的所有.css文件。这也是可能的ant脚本。

Flex stylesheets are parsed by the compiler and bundled with their assets (graphics, usually) into a swf file, which can then be loaded at runtime. I've got a project with a fixed number of styles (currently 4: old corporate style, new corporate style, and high contrast versions of both). Using Flash Builder (Eclipse with Flex IDE plugin) I'm able to have all .css files compiled to .swf files alongside the primary project artifact .swf file. This is also possible with ant scripts.

我目前的理解是,Maven的希望只能创建每个项目(POM文件)一个缺陷,但可能有增加了一些额外的人(如拉链包装)。对于可扩展性的原因 - 我有一个复杂的设置许多库和模块项目,其中几人有自己单独的样式表 - 这将是非常不切实际的项目分成主项目及副本,每个样式表。至少在Eclipse项目方面,有一些子文件夹与主POM文件refered在每个POM文件,所有并参照相同的src /位置(和正在内的一个Eclipse项目)可能会工作。虽然这是丑陋的,需要单独artifactIds每个,仍然需要以某种方式组装起来。

My current understanding is that Maven wants to only create one artifact per project (POM file), but may have some additional ones added (like zip packaging). For scalability reasons - I've got a complex setup of many library and module projects, several of them having their own individual stylesheets - it would be very impractical to split up the projects into the 'main' project and copies for each stylesheet. At least on the Eclipse project side, having some subfolders with POM files in each, all refered by a master pom file and referring the same src/ location (and being inside one Eclipse project) would probably work. Though that's ugly and needs individual artifactIds for each, and still need to be assembled somehow.

最重要的是要能够有一个包含了(Eclipse中)总装项目主SWF文件和每个样式表swf文件(而像本地化的文本在运行时加载的一些静态文件)。这将是其中的一些项目,我所描述大型组件的一部分在一个单独的问题

The important thing is to be able to have a final assembly which contains the (Eclipse) projects main swf file and each stylesheets swf file (and some static files like localized texts to be loaded at runtime). This will be part of a large assembly of several of those projects which I've described in a separate question.

我使用的Eclipse 3.6.1(太阳神)使用Flash Builder插件(即FLEX4),目标定位的Flex SDK 3.5(flash播放器10.0)。我已经安装了Maven的3.0.2,使用Sonatypes 的Flexmojos-Maven的插件3.7.1 (因为它似乎比一个更积极Servebox )。我手动创建POM文件,我的项目和他们的工作(虽然只编译的SWF文件的假象,这取决于我指定的主。作为或.css文件与sourcefile之一)

I'm using Eclipse 3.6.1 (Helios) with Flash Builder Plugin (i.e. Flex4), targetting Flex SDK 3.5 (FlashPlayer 10.0). I've installed Maven 3.0.2, using Sonatypes flexmojos-maven-plugin 3.7.1 (as it seems more active than the one from Servebox). I've manually created pom files for my projects and they work (though only compiling one swf artifact file, depending on whether I specify the main .as or one of the .css files as sourceFile)

我已经尝试了一些日子,现在明白Maven的路(这似乎是专为Java和不完全拟合针对Flex),但不能得到这个工作让我有一个单一的项目,或者至少一个组件与它的一切。

I've tried for some days now to understand "The Maven Way" (which seems to be tailored for Java and not fitting perfectly for Flex), but couldn't get this to work so that I have a single project, or at least a single assembly with everything in it.

什么是做到这一点这里最好的方法是什么?

What would be the best way to do this here?

推荐答案

我没有找到一个方法来创建同一个POM文件多的文物,甚至没有运行flexmojo编译目标超过一次(即使与执行绑定标签,Maven会抱怨)。于是,我找到了最好的方法是使用一个非常类似的解决方案,因为我的整个项目,我所描述的在这个问题上,包括我的解决方案,并且我建议阅读,因为我将立足于这一点。我曾希望一个不太hackish的解决方案,在这里,使用这种多项目的做法似乎有点脏了我。这也是为什么我分裂的问题,从而让我荣幸地被注意到了杰夫·阿特伍德本人:)

I did not find a way to create multiple artifacts from the same POM file, not even to run the flexmojo compile target more than once (even when binding with execution tag, Maven will complain). So the best way I found was using a quite similar solution as for my overall project, which I've described in this question, including my solution, and which I suggest reading, as I'll base on that. I had hoped for a less hackish solution here, using this multi-project-approach seems a bit dirty to me. That's also why I split the question, which in turn got me the honor of being noticed by Jeff Atwood himself :)

我不希望只使用一个Eclipse项目为我的插件,但需要几个文件夹使用多个多金属氧酸盐。我的文件夹结构如下所示:

I do want to use only one Eclipse project for my plugin, but need several folders to use multiple POMs. My folder structure looks like this:

colored_plugin/src/colored_plugin_main.as
colored_plugin/src/green.css
colored_plugin/src/...
colored_plugin/src/assets/rainbow.jpg          <- will be embedded into stylesheet swf file
colored_plugin/WebContent/assets/labels.xlf
colored_plugin/WebContent/config/config.xlf
colored_plugin/POMs/assembly/pom.xml
colored_plugin/POMs/plugin/pom.xml
colored_plugin/POMs/style1/pom.xml
colored_plugin/pom.xml
master_build/pom.xml
master_build/swf-assembly.xml
master_build/css-assembly.xml
master_build/plugin-assembly.xml
master_build/assembly/pom.xml
master_build/assembly/final-asembly.xml

我使用的master_build文件夹来存储我的SWF组件文件,我简单的SWF项目的中心位置,所以我把我包含在相同的位置样式插件组装描述符。

I'm using the master_build folder as a central location to store my swf-assembly file for my simple swf projects, so I put my assembly descriptor for the plugins containing stylesheets in the same location.

聚甲醛编译插件(多金属氧酸盐/插件/ pom.xml的)颇为相似,简单的SWF项目之一(见其他问题):

The POM compiling the plugin (POMs/plugin/pom.xml) is quite similar to the one of the simple swf projects (see other question):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>de.zefiro.maven.example</groupId>
        <artifactId>colored_plugin_internal</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../</relativePath>
        </parent>

    <name>Colored Plugin (Plugin Executeable)</name>
    <artifactId>${project.parent.artifactId}_swf</artifactId>
    <packaging>swf</packaging>

    <build>
        <sourceDirectory>../../src</sourceDirectory>

        <!-- This name needs to be exactly specified, as the runtime will load it as it's specified in the configuration xml -->
        <finalName>SampleProjectModuleColored</finalName>

        <plugin>
            <groupId>org.sonatype.flexmojos</groupId>
            <artifactId>flexmojos-maven-plugin</artifactId>
            <version>3.7.1</version>
            <configuration>
                <sourceFile>colored_plugin_main.as</sourceFile>
            </configuration>
        </plugin>

        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>../../../master_build/swf-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>WebContent-packaging</id>
                        <phase>package</phase>
                        <goals><goal>single</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${group-id}</groupId>
            <artifactId>project_swc</artifactId>
            <version>${project.version}</version>
            <scope>${zefiro.swf.scope}</scope> <!-- tell Flex Mojo that we want to compile using runtime shared libraries (rsl) -->
            <type>swc</type>
        </dependency>
        [...]
    </dependencies>

</project>

的POM样式表是它的一个几乎相同的版本:.css文件指定为源,这里不再需要依赖关系(至少在我的情况),但它仍然需要打包,这样我以后可以引用(和重新包装),其用于组装。

The POM for the stylesheet is a nearly identical version of it: the .css file is specified as source, dependencies are not needed here (at least in my case), but it still needs to be packaged so that I can later reference (and repack) it for the assembly.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>de.zefiro.maven.example</groupId>
        <artifactId>colored_plugin_internal</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../</relativePath>
    </parent>

    <name>Colored Plugin (Stylesheet 'Green')</name>
    <artifactId>${project.parent.artifactId}_css_green</artifactId>
    <packaging>swf</packaging>

    <build>
        <sourceDirectory>../../src</sourceDirectory>
        <finalName>style_green</finalName>
        <plugins>
            <plugin>
                <groupId>org.sonatype.flexmojos</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <version>3.7.1</version>
                <configuration>
                    <sourceFile>green.css</sourceFile>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>../../../master_build/css-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>WebContent-packaging</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

组装描述符也是一个简化版本,只有包装SWF文件。我不知道它的需要和可能的组件可以直接与默认的Maven神器完成,但它是最容易的,我只是不喜欢它在所有其他项目。

The assembly descriptor is also a simplified version, only packaging the swf file. I'm not sure it's needed and perhaps the assembly could be done with the default Maven artifact directly, but it was easiest for me to just do it like in every other project.

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>Stylesheet</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <!-- Take the stylesheet swf artifact (only, not the other stuff which is generated there) -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.swf</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

组装项目有这个POM:

The assembly project has this POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>de.zefiro.maven.example</groupId>
        <artifactId>colored_plugin_internal</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../</relativePath>
    </parent>

    <name>Colored Plugin (Assembly)</name>
    <artifactId>colored_plugin</artifactId>
    <packaging>pom</packaging>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>../../../master_build/plugin-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>Plugin_assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${group-id}</groupId>
            <artifactId>${project.parent.artifactId}_swf</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
            <classifier>WebContent</classifier>
        </dependency>
        <dependency>
            <groupId>${group-id}</groupId>
            <artifactId>${project.parent.artifactId}_css_green</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
            <classifier>Stylesheet</classifier>
        </dependency>
    </dependencies>
</project>

该插件组装描述符包这一切都在一起。这也是在一个中心位置,因此在编写一个通用的方式:它引用组ID和呼叫POM的artifactId和利用我介绍了命名规则。最后一个项目将是建设大会POM,从而出现我指定了'好'的artifactId。主要项目POM(见下文),得到一个手动而得名,而所有其他项目(主要应用和所有样式表)会自动源于此而产生Maven的文物是仅在内部使用。我有一个以上的样式,让我真正的组装POM列出了多个样式表的依赖关系(相对于这个例子),而我的装配描述把他们全部使用通配符。

The plugin assembly descriptor packs all this together. It's also in a central location and thus written in a generic way: It references group-id and artifactId from the calling POM and utilizing a name convention I've introduced. The final project will be build by the assembly POM, thus there I specify the 'nice' artifactId. The main project POM (see below) gets a manually derived name, while all other projects (main application and all stylesheets) are automatically derived from this and produce Maven artifacts which are only used internally. I've more than one stylesheet, so my real assembly POM lists multiple stylesheet dependencies (as opposed to this example), whereas my assembly descriptor takes them all using a wildcard.

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>WebContent</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <!-- add the WebContent folder -->
        <fileSet>
            <directory>../../WebContent</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <!-- add plugin main executable -->
        <dependencySet>
            <includes>
                <include>${group-id}:${project.parent.artifactId}_swf:zip:WebContent:${project.version}</include>
            </includes>
            <useProjectAttachments>true</useProjectAttachments>
            <unpack>true</unpack>
            <outputDirectory>/</outputDirectory>
        </dependencySet>
        <!-- add stylesheets -->
        <dependencySet>
            <includes>
                <include>${group-id}:${project.parent.artifactId}_css_*:zip:Stylesheet:${project.version}</include>
            </includes>
            <useProjectAttachments>true</useProjectAttachments>
            <unpack>true</unpack>
            <outputDirectory>/assets/styles</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

请注意,我用相同的ID,此装配描述,因为我已经用了简单的SWF项目(如图我的其他问题)。这使得它更容易指定正确的神器在整体组装的插件,因为我可以只使用'的WebContent作为分类为我所有的项目。

Note that I used the same ID for this assembly descriptor as I've used for the simple swf projects (as shown in my other question). This makes it easier to specify the correct artifact in the overall assembly plugin, as I can just use 'WebContent' as classifier for all my projects.

最后,主POM为我的项目只是一个小主叫方为那些其他的POM:

Finally, the main POM for my project is just a small caller for those other POMs:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>de.zefiro.maven.example</groupId>
        <artifactId>full_build</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../master_build</relativePath>
    </parent>

    <name>Colored Plugin</name>
    <artifactId>colored_plugin_internal</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>pom/plugin</module>
        <module>pom/style1</module>
        <module>pom/assembly</module>
    </modules>

</project>

一个新的样式表可以通过添加:

A new stylesheet can be added by:

  • 添加red.css样式表和所有附带的文件到src /目录
  • 复制colored_plugin /多金属氧酸盐/ STYLE1 / pom.xml的,以colored_plugin /多金属氧酸盐/蓝紫魅力/ pom.xml的
  • 将它添加到colored_plugin / pom.xm作为一个模块
  • 将它添加到colored_plugin /多金属氧酸盐/组装/ pom.xm作为依赖
  • 由于通配符和命名约定,装配描述符(/master_build/plugin-assembly.xml)不需要改变

最后一个项目神器是要消耗一个zip文件(并与其他项目合并)我的主装配,并包含这些文件:

The final project artifact is a zip file to be consumed (and merged with the other projects) by my master assembly and contains those files:

SampleProjectModuleColored.swf
assets/labels.xlf
assets/styles/style_green.swf
config/config.xlf

它会被存储在库中的

It will be stored in the repository as

de.zefiro.maven.example:colored_plugin:zip:WebContent:1.0-SNAPSHOT

这篇关于使用Maven构建Flex项目包括样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆