gpt4 book ai didi

java - eclipse + Maven + Tomcat : testing web apps when the WAR is built with custom options

转载 作者:行者123 更新时间:2023-11-28 22:30:44 24 4
gpt4 key购买 nike

我正在使用带有“m2eclipse”插件的 Eclipse (Helios)。我正在开发一个基于 Maven 的 Web 应用程序项目,我在 Eclipse 中设置的本地 Tomcat 服务器上对其进行了测试。

一般来说,这或多或少很管用。 “m2eclipse”有时可能不稳定……但在大多数情况下,它使我的 POM 和我的 Eclipse 项目设置保持同步,并且同样使已部署的代码在 Tomcat 中保持最新。

但是,最近我又添了一个皱纹。我有一个 JavaScript 包含文件,在从测试环境到实际生产环境时需要有所不同。差异太大,无法通过 Maven 过滤和 token 替换来干净地处理。我需要的是在我的项目中保留两个单独的文件,并且只部署适合构建配置文件的文件。

我在我的 Maven POM 中使用了一些“targetPath”技巧来完成这个:

<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>

这构建了一个完美的 WAR 文件,当我将它部署到某个外部 Tomcat 服务器时它工作正常。然而,问题在于 Eclipse 在 Eclipse 中运行 Tomcat 时不使用该 WAR 文件。相反,Eclipse 使用应用程序的分解版本,部署到一个神秘的目录,如下所示:

<workspace>/.metadata/.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”被替换为“Deployment Assembly”选项。您可以在此“部署程序集”选项(项目属性 ---> 部署程序集)中配置要部署到 Eclipse 内部运行的 tomcat 的文件

enter image description here

关于java - eclipse + Maven + Tomcat : testing web apps when the WAR is built with custom options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19988364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com