使用 Maven 进行 Coldfusion 项目 [英] Using Maven for Coldfusion project

查看:15
本文介绍了使用 Maven 进行 Coldfusion 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须处理相当丑陋和大块的 ColdFusion 代码,直到今天这些代码仍然通过生产服务器上的直接修改来维护(不要问).我设法从欺骗和备份中清理它并将其放入 Subversion,现在我需要选择一个制作系统才能将其放入持续构建(TeamCity)和预定版本中.令我惊讶的是,我在 如何使用 Maven 改造 CF 项目,所以问题是 - 有没有人有在 CF 上成功使用 Maven 的经验,以及人们通常使用什么来管理大型 CF 项目?您的建议、提示和链接将不胜感激因为我不想引发宗教战争 - Maven 几乎是公司标准(与 Ant 相比)

I have to deal with what is pretty ugly and large blob of ColdFusion code which up to this day is maintained by direct modifications on production server (don't ask). I managed to clean it up from dupes and backups and put it into Subversion, now I need tp pick a make system to be able to put this onto continuous build (TeamCity) and also scheduled releases. To my surprise I only found pretty much a single blog article on how to retrofit CF project with Maven, so the question is - does anyone have experience successfully using Maven on CF and what in general people use to manage large CF projects? Your suggestions, tips and links will be much appreciated Since I don't want to start religions wars - Maven is pretty much company standard (vs Ant)

推荐答案

首先,这里是另一个你可能会发现有用的博客.

First, here's another blog you might find helpful.

build-tools-maven-and-coldfusion

我没有尝试使用 Maven 构建 ColdFusion,但我有为一家大公司管理 Maven 构建的经验.您需要考虑一些事项.

I haven't tried to build ColdFusion with Maven, but I have experience with managing Maven builds for a large company. There are a few things for you to consider.

项目结构

Coldfusion cfm 和 cfc 文件应该放在 src/main/resources 中,以便将它们捆绑在 jar 中(上面引用的博客覆盖了 Maven 约定,将它们放在 src 中.这没关系,但如果你以后需要向项目中添加任何其他内容).

Coldfusion cfm and cfc files should be put in src/main/resources so they are bundled in the jar (the blog referenced above overrides the Maven convention to put them in src. this is ok, but could be a problem if you later need to add anything else to the project).

我可能会将 cfc 和 cfm 文件保存在单独的项目中,并使用适当的依赖声明来链接它们,这样可以将您的 cfc 项目保留为库并有助于重用.cfc 项目的粒度也值得考虑.通常,Maven 的依赖管理可以帮助您保持较小的工件,而无需担心找到所有的 jar.

I'd probably keep cfc and cfm files in separate projects with appropriate dependency declarations to link them, this keeps your cfc projects as libraries and helps reuse. It is also worth considering the granularity of the cfc projects. Generally Maven's dependency management helps you keep artifacts small, with little need to worry about finding all the jars.

部署

交付工件的最简单方法是使用 maven-war-plugin 创建一个包含您的工件及其所有传递依赖项的战争.这使得每个应用程序都是独立的,这很有用.这样做的缺点是您最终会重复捆绑相同的工件,而且它们可能非常大.为了缓解这种情况,您可以使用 assembly-plugin 创建自定义包,不包括通用组件,或者您可以指定某些组件(例如 ColdSpring)在范围内提供,这意味着它们不会包含在战争中.

The simplest way to deliver the artifacts is to use the maven-war-plugin to create a war containing your artifacts and all their transitive dependencies. This makes each application self-contained, which can be useful. The downside of this is that you'll end up bundling the same artifacts repeatedly and they can be quite large. To mitigate this you can either use the assembly-plugin to create custom packages excluding the common components, or you can specify that certain components (e.g. ColdSpring) are scope provided, this means they won't be included in the war.

版本管理

Maven 鼓励依赖项的扩散,默认情况下每个依赖项声明都有一个版本,这可能会导致维护问题,尤其是当您想要提高外部依赖项的版本时.您可以通过定义父 POM 或应用程序"POM 来缓解这种情况.要么有一个 dependencyManagement 部分声明常见工件的详细信息(groupId、artifactId 和版本).任何从父级继承的 POM 都不需要声明依赖版本,因为它将被继承(注意这并不意味着所有子级都将拥有所有依赖项,只是任何声明依赖项的都不需要声明版本).如果你定义了一个带有包装pom"和一个dependencyManagement 部分的app"项目,你可以使用范围import 来引用它(从Maven 2.0.9 开始),这将从"app"项目到项目POM.有关详细信息,请参阅依赖文档.

Maven encourages a proliferation of dependencies, by default each dependency declaration has a version, this can cause maintenance issues, particularly when you want to bump the version of an external dependency. You can mitigate this by defining a parent POM or an "app" POM. Either would have a dependencyManagement section declaring the details (groupId, artifactId, and version) for common artifacts. Any POM inheriting from the parent need not declare the dependency version as it will be inherited (note this doesn't mean that all children will have all dependencies, only that any that declare a dependency don't need to declare the version). If you define an "app" project with packaging "pom" and a dependencyManagement section, you can reference it with scope import (from Maven 2.0.9 onwards), this will import the dependencyManagement section from the "app" project to the project POM. See the dependency documentation for more details.

如果您在dependencyManagement 部分中声明具有范围的依赖项,则该范围将被继承,除非它在子POM 中被覆盖.与上面的部署部分相关,这意味着您可以在父级中声明公共库范围provided,以确保它们不会捆绑在每个应用程序中.

If you declare a dependency with a scope in the dependencyManagement section, that scope will be inherited unless it is overridden in the child POM. Related to the deployment section above, this means that you can declare the common libraries scope provided in the parent to ensure they are not bundled in each applciation.

命名约定您需要为包命名约定以避免冲突.最好遵循 Maven 约定并使用类似于 java 包的 groupIds(org.apache.maven 用于 maven.apache.org)和工件的 jar 名称.此约定将为 ColdSpring 提供 groupIdorg.coldspringframework"和 artifactIdcoldspring".

Naming Conventions You'll need a naming convention for the packages to avoid collisions. It's probably best to follow the Maven convention and use java package-like groupIds (org.apache.maven for maven.apache.org) and the jar name for the artifact. This convention would give the groupId "org.coldspringframework" and artifactId "coldspring" for ColdSpring.

整个公司可能需要进一步区分.例如,如果您有一个网络和核心团队,您可以为网络团队提供 groupIds com.mycompany.web.* 和核心团队 com.mycompany.core.*

Further distinctions might need to be made across the company. For example, if you have a web and core team, you could give the web team the groupIds com.mycompany.web.* and the core team com.mycompany.core.*

依赖管理

您需要将 CFC 包添加到 Maven 存储库,例如 Nexus,以便它们可以访问整个企业的其他构建.

You'll need to add your CFC packages to a Maven repository such as Nexus so they are accessible to other builds across the enterprise.

如果您想将 CFC 包与 jar 分开.您可以指定自定义打包类型,这样它们就不会与任何 Java 工件混淆.如果您创建自定义打包类型,则工件可以具有.jar"扩展名,但任何依赖项声明都必须具有类型集.

If you want to keep the CFC packages separate to the jars. You can specify a custom packaging type, so that they won't be mixed up with any Java artifacts. If you create a custom packaging type, the artifacts can have the ".jar" extension, but any dependency declaration must have the type set.

以下是遵循这些约定的示例:

Here's an example following those conventions:

<dependency>
  <groupId>org.coldspringframework</groupId>
  <artifactId>coldspring</artifactId>
  <version>1.2</version>
  <!--custom packaging type helps keep separate from Java artifacts-->
  <type>cfc</type>
</dependency>

Nexus 书中有一段描述 自定义生命周期(点击链接了解更多详细信息.本质上,您需要创建一个带有 META-INf/plexus/components.xml 的插件来描述 plexus 机制(使用什么存档器,输出什么扩展等).

There's a section in the Nexus book that describes custom lifecycles (follow the links for more details. Essentially you need to create a plugin with a META-INf/plexus/components.xml to describe the plexus mechanics (what archiver to use, what extension to output etc).

components.xml 看起来像这样:

The components.xml would look something like this:

<component-set>
  <components>
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>cfc</role-hint>
      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
      <configuration>
        <phases>
          <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
          <package>com.hsbc.maven.plugins:maven-jar-plugin:jar</package>          
          <install>org.apache.maven.plugins:maven-install-plugin:install</install>
          <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
        </phases>
      </configuration>
    </component>
    <component>
      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
      <role-hint>cfc</role-hint>
      <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
      <configuration>
        <extension>jar</extension>
        <type>cfc</type>
        <packaging>cfc</packaging>
      </configuration>
    </component>
     <component>
       <role>org.codehaus.plexus.archiver.Archiver</role>
       <role-hint>cfc</role-hint>
       <implementation>org.codehaus.plexus.archiver.zip.ZipArchiver</implementation>
       <instantiation-strategy>per-lookup</instantiation-strategy>
     </component>
     <component>
       <role>org.codehaus.plexus.archiver.UnArchiver</role>
       <role-hint>cfc</role-hint>
       <implementation>org.codehaus.plexus.archiver.zip.ZipUnArchiver</implementation>
       <instantiation-strategy>per-lookup</instantiation-strategy>
     </component>
  </components>
</component-set>

这篇关于使用 Maven 进行 Coldfusion 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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