Eclipse + Maven + Tomcat:当使用自定义选项构建WAR时,测试Web应用程序 [英] Eclipse + Maven + Tomcat: testing web apps when the WAR is built with custom options

查看:97
本文介绍了Eclipse + Maven + Tomcat:当使用自定义选项构建WAR时,测试Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse(Helios),使用m2eclipse插件。我正在开发一个基于Maven的Web应用程序项目,我在Eclipse中安装的本地Tomcat服务器上进行测试。



一般来说,这个工作或多或少都是好的。 m2eclipse有时可以是片状的,但在大多数情况下,它保持我的POM和我的Eclipse项目设置同步,同样将部署的代码保留在Tomcat中。



<不过最近我加了一个皱纹。从测试环境到实际的生产环境,我有一个JavaScript包含文件需要不同。差异太大,无法通过Maven过滤和令牌替换进行干净处理。我需要的是在我的项目中保留两个单独的文件,并且仅部署适用于构建配置文件的文件。



我在我的Maven POM:

 < plugin> 
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-war-plugin< / artifactId>
< version> 2.1.1< / version>
< configuration>
< webResources>
< resource>
<! - 从prod或non-prod子目录中获取东西,并将其复制一级 - >
< directory> src / main / webapp / js / $ {profile.name}< / directory>
< targetPath> js< / targetPath>
< / resource>
< resource>
<! - 现在不要部署这些特定于个人资料的子目录 - >
< directory> src / main / webapp / js< / directory>
< excludes>
< exclude> prod< / exclude>
< exclude> non-prod< / exclude>
< / excludes>
< / resource>
< / webResources>
< / configuration>
< / plugin>

这构建了一个完美的WAR文件,当我部署一些外部的Tomcat服务器时,文件可以正常工作。但是,问题是Eclipse在Eclipse中运行Tomcat时不会使用该WAR文件。相反,Eclipse可以使用应用程序的分解版本,并将其部署到如下隐藏目录:

 < workspace> /。元数据/ .plugins / org.eclipse.wst.server.core / tmp1 / wtpwebapps / MyApp 

。 ..并且显然应用程序的文件被复制到此位置前一个Maven做上面显示的小小的诡计。因此,当在Eclipse内部进行本地测试时,预期的位置根本不存在JavaScript包含。



有没有办法解决这个问题?可能Eclipse更改或Maven更改将文件从Maven的目标目录拉到Eclipse的wtpwebapps目录?也许还有另外一种方法可以解决个人资料 - 包含文件的问题?

解决方案

从eclipse(Helios)3.6开始,选项Java EE Module Dependencies由部署程序集选项替代。您可以在部署程序集选项(项目属性--->部署程序集)中将要部署的文件配置到Eclipse内运行的tomcat。




I am using Eclipse (Helios), with the "m2eclipse" plugin. I am working on a Maven-based web application project, which I test on a local Tomcat server that is setup inside Eclipse.

Generally, this works more or less great. "m2eclipse" can sometimes be flaky... but for the most part it keeps my POM and my Eclipse project settings in sync, and likewise keeps the deployed code current in Tomcat.

However, recently I've added a wrinkle. I have one JavaScript include file that needs to be different when going from the test environment to the real production environment. The differences are too significant to be cleanly handled by Maven filtering and token substitution. What I needed was to keep two separate files in my project, and only deploy the one appropriate for the build profile.

I accomplished this with some "targetPath" trickery in my Maven POM:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1.1</version>
   <configuration>
      <webResources>
         <resource>
            <!-- take the stuff from a "prod" or "non-prod" subdirectory and copy it one level up -->
            <directory>src/main/webapp/js/${profile.name}</directory>
            <targetPath>js</targetPath>
         </resource>
         <resource>
            <!-- now don't deploy those profile-specific subdirectories -->
            <directory>src/main/webapp/js</directory>
            <excludes>
               <exclude>prod</exclude>
               <exclude>non-prod</exclude>
            </excludes>
         </resource>
      </webResources>
   </configuration>
</plugin>

This builds a perfect WAR file, which works fine when I deploy it some external Tomcat server. However, the problem is that Eclipse does NOT use that WAR file when running Tomcat inside of Eclipse. Instead, Eclipse works with an exploded version of the application, deployed to a cryptic directory like this:

<workspace>/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/MyApp

... and apparently the app's files are copied to this location PRIOR TO Maven doing the little trickery shown above. Therefore, when testing locally inside of Eclipse, no JavaScript include is present at all in the expected location.

Is there a way around this problem? Maybe an Eclipse change, or a Maven change, to pull the file from Maven's "target" directory to Eclipse's "wtpwebapps" directory? Maybe there's another approach to solving the profile-specific-include-file issue altogether?

解决方案

Starting from eclipse (Helios) 3.6 , the option "Java EE Module Dependencies" is replaced by "Deployment Assembly" option . You can configure which files to be deployed to the tomcat running inside of Eclipse in this "Deployment Assembly" option (Project Properties ---> Deployment Assembly )

这篇关于Eclipse + Maven + Tomcat:当使用自定义选项构建WAR时,测试Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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