java - 使用 m2eclipse 结合 WTP 构建 WAR(处理 webResources)

标签 java eclipse maven-2 m2eclipse eclipse-wtp

我有一个使用 maven(即 maven-war-plugin)构建的 Web 应用程序。对于每次代码修改,我们都必须手动启动 maven 并重新启动应用程序服务器。现在,为了减少构建周期的开销,我想使用 WTP 来发布 webapp。

现在,我们使用 Maven 进行资源处理,并且在构建 Web 应用程序时在我们的 POM 中定义了一些额外的 Maven 任务。因此 m2eclipse 似乎是一个自然的解决方案。

我已经了解了 Maven 构建器正在运行这些任务并正确过滤资源。但是,当我选择“在服务器上运行”时,WAR 文件看起来不像是在 Maven 中构建的。

猜测这是因为 WTP 实际上构建了 WAR,而不是 m2eclipse 构建器。因此,即使我们在 POM 中配置了 maven-war-plugin,也不会使用这些设置。

下面是我们的 maven-war-plugin 配置的片段。在“webResources”下配置的内容没有被拾取,出现:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
 <outputDirectory>${project.build.directory}</outputDirectory>
 <workDirectory>${project.build.directory}/work</workDirectory>
 <webappDirectory>${project.build.webappDirectory}</webappDirectory>
 <cacheFile>${project.build.webappDirectory}/webapp-cache.xml</cacheFile>
 <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
 <nonFilteredFileExtensions>
  <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
  <nonFilteredFileExtension>png</nonFilteredFileExtension>
  <nonFilteredFileExtension>gif</nonFilteredFileExtension>
  <nonFilteredFileExtension>jsp</nonFilteredFileExtension>
 </nonFilteredFileExtensions>
 <webResources>
 <!-- Add generated WSDL:s and XSD:s for the web service api. -->
   <resource>
   <directory>${project.build.directory}/jaxws/wsgen/wsdl</directory>
   <targetPath>WEB-INF/wsdl</targetPath>
   <filtering>false</filtering> 
   <includes>
     <include>**/*</include>
   </includes>
 </resource>               
 </webResources>
 </configuration>

我是否需要重新配置这些资源以便在别处处理,或者是否有更好的解决方案?

最佳答案

为了在其他人遇到相同问题时填写我自己的问题的答案,我最终将以下内容添加到我的 webapp 项目中:

<resource>
  <directory>${project.build.directory}/jaxws/wsgen/wsdl</directory>
  <filtering>true</filtering>
  <targetPath>${project.basedir}/src/main/webapp/WEB-INF/wsdl</targetPath>
  <includes>
    <include>**/*</include>
  </includes>
</resource>

(在 build 下的 resources 元素内)。

它工作正常,因为我的 WSDL 文件是在 generate-resources 阶段生成的,并将它们放在 target/jaxws/wsgen/wsdl 中。然后将它们移入 src/main/webapp/WEB-INF/wsdl,WTP 构建器在构建 WAR 文件时从中选取它们。

注意:我应该提到我现在遇到 Maven 的 eclipse 插件的一些问题(即 mvn eclipse:eclipse),因为显然你不允许在 targetPath 中有绝对路径。尚未找到令人满意的解决方法...

关于java - 使用 m2eclipse 结合 WTP 构建 WAR(处理 webResources),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2856055/

相关文章:

java - 如何在 Eclipse 上导出带有图像的 jar?

maven-2 - 为什么添加测试 jar 会破坏此 Maven 构建?

java - 如何在 Liquibase 中模仿 Hibernate hbm2ddl "create"行为?

java - 返回带有 Spring MVC 的 ResponseEntity 的流

java - If-Modified-Since 日期格式

java - 我的 fragment Activity 内的按钮不起作用

maven-2 - 如何递归地解决 Maven 2 插件中的依赖项

java - 文件名上的黄色背景在 Intellij 中意味着什么?

java - 如何在 eclipse 和 tomcat 中创建简单的(servlet)java ee 项目

android - 插件 org.eclipse.ui 中未处理的事件循环异常