zoukankan      html  css  js  c++  java
  • Flex 中Maven的使用

    Maven是为了简化Java项目的构建而建立的工具,通过设置相关的依赖等信息可以自动从网络下载对应的版本的库。

    Flex的开发资源中有很多都是和Java端集成的,因此网络上很多的项目都是基于Maven形式的,如果搞不定这个,那运行这些例子估计很困难。

    上一篇 http://www.cnblogs.com/2018/archive/2011/06/02/2067641.html 主要是Flash Builder等IDE中的使用,这个主要讲讲命令行的形式构建,毕竟Java的环境下这个形式还是很多的。对于.net的开发者来说,这个过程也算一个小的挑战(不同的版本、各种的设置、版本冲突等等,不过一些都是开源的资料还是比较多的,不过需要花功夫去学习和理解)

    主页:http://Maven.apache.org/download.html

    常用名令:http://blog.csdn.net/shangpusp/archive/2010/02/07/5297340.aspx

    如果需要详细了解Maven的信息,参考这个简明的手册(一百多页): http://www.sonatype.com/index.php/Support/Books/Maven-By-Example 

    Maven Eclipse Plug-in

    可以在Eclipse中安装下面的插件,这样就可以IDE建立和使用Maven的项目了

    http://m2eclipse.sonatype.org/sites/m2e

    http://m2eclipse.sonatype.org/sites/m2e-extras

    plug-in

    mvn clean 使用core plug-in

    mvn jetty:run 需要在pom.xml.中指定Jetty plug-in

    Maven plug-ins列表参考地址:

    http://mvnrepository.com/

    Maven 配置的三个层面:

    •  Project: most static configuration occurs in pom.xml 在项目文件Pom.xml

    •  Installation: (Maven installation)/conf/setting的安装层次

    •  User:  特定用户 ${user.home}/.m2/setting.xml

    以上三个不同的配置信息可以根据实际情况选择配置

    Jetty配置例子

    项目中一般使用JSP容器进行运行的测试方法,此处使用Jetty

    Jetty 的POM XML文件

    <plug-in>

           <groupId>org.mortbay.jetty</groupId>

           <artifactId>Maven-jetty-plug-in</artifactId>

           <version>6.1.19</version>

           <configuration>

           <contextPath>/yourContextRoot</contextPath>

           <scanIntervalSeconds>4</scanIntervalSeconds>

           <scanTargetPatterns>

                  <scanTargetPattern>

                         <directory>

                                 src/main/webapp/WEB-INF

                         </directory>

                         <excludes>

                                 <exclude>**/*.jsp</exclude>

                         </excludes>

                         <includes>

                                <include>**/*.properties</include>

                                <include>**/*.xml</include>

                         </includes>

                    </scanTargetPattern>

            </scanTargetPatterns>

            </configuration>

    </plug-in>

    Maven中配置Jetty

    http://maven.apache.org/settings.html

    D:\softwares\apache-maven-2.2.1\conf\settings.xml

      <pluginGroups>

        <!-- pluginGroup

         | Specifies a further group identifier to use for plugin lookup.

        <pluginGroup>com.your.plugins</pluginGroup>

        -->

         <pluginGroup>org.mortbay.jetty</pluginGroup>

    </pluginGroups>

    其他配置和本地安装例子

    配置Spring 库自动下载的例子:

    <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring</artifactId>

            <version>2.5.2</version>

    </dependency>

    <dependency>

           <groupId>org.springframework</groupId>

           <artifactId>spring-test</artifactId>

           <version>2.5.2</version>

           <optional>true</optional>

    </dependency> 

    Maven 现在本地仓库中找依赖组件(${user.home}/.m2/目录下),然后在远程仓库中找,如果都没有找到,提示自己安装。

    自己本地安装的方法:

    • 先找到相关的库文件
    • mvn install:install-file -DgroupId= org.springframework -DartifactId=spring –Dversion=2.5.2 -Dpackaging=jar -Dfile=spring-2.5.2 .jar

    以上命令就把相关内容安装到本地仓库 ${home}/.m2/repository/

    archetype

    Basically, an archetype is like a template for your project that is reusable for similar projects. The archetype will create the directory structure, including all the files needed, and download all plug-ins and dependencies needed by the project, saving you a lot of time in the creation and configuration of your project. [意思就是可以建立项目的框架架构,这样以后其他的项目可以在这些框架结构基础上再发展]

    以上是两个构建Flex的archetype.

    FNA

    FNA is an open source project started by Adobe consulting that helps Java and Flex development with open source projects and Maven archetypes. You can see and read more about FNA at http://code.google.com/p/fna-v2/ You can find more interesting and useful Flex-Java archetypes at http://fna-v2.googlecode.com/svn/trunk/mvn_archetypes/such as:

    •  flex-cairngorm-stubbed-crud-archetype

    •  flex-cairngorm-flexunit-archetype

    •  flex-library-archetype

    Flex Mojos Maven plugin

    http://flexmojos.sonatype.org/

    http://www.sonatype.com/book

    http://flexmojos.sonatype.org/getting-started.html

    一个例子:

    mvn archetype:create -DarchetypeGroupId=org.foj -DarchetypeArtifactId=flex-mojos-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=org.foj -DartifactId=flex-bugs-ria -DremoteRepositories=http://flexonjava.googlecode.com/svn/repository

    http://filippodipisa.artifactoryonline.com/filippodipisa/libs-releases-local/archetype-catalog.xml 

    命令

    编译源代码

    mvn compile

    测试代码

    mvn test 

    构建项目[编译测试]并安装到repository

    mvn install

    构建项目[编译不测试]并安装到repository

    mvn install –DskipTests

    编译测试和安装

    指定测试的Flash文件

    mvn install -DflashPlayer.command=d:\FlashPlayer.exe

    打包

    mvn package 

    把webapp打部署到Jetty运行

    mvn jetty:run

    把webapp打到war 包并自动部署到Jetty运行

    mvn jetty:run-war

    生成eclipse项目

    mvn eclipse:eclipse  清除mvn eclipse:clean

    生成Flex/Flash Builder项目

    mvn flexmojos:flexbuilder

    [http://www.sonatype.com/books/mvnref-book/reference/flex-dev-sect-goals.html#flex-dev-sect-flexbuilder ]

    有了这些知识,对于Java和Flex集成时涉及的很多自动化Maven构建项目可以参考使用了。

    .net下的nuget http://www.nuget.org/ 和maven目前也基本是相同的功能,只不过是.net的领域,看来两者是不断的互相学习和进步。

  • 相关阅读:
    SIEM思考
    PowerDesigner15在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
    Mongo驱动
    RsysLog
    vi全局替换方法
    RPM
    hdu1195 Open the Lock (DFS)
    调制:调幅(AM)与调频(FM)
    调制:调幅(AM)与调频(FM)
    追本溯源 —— 诗词、名言
  • 原文地址:https://www.cnblogs.com/2018/p/2068745.html
Copyright © 2011-2022 走看看