带有 maven-eclipse-plugin 的 Maven webapp 不会生成
我使用 eclipse:eclipse 目标来生成 Eclipse 项目环境。部署工作正常。该目标为所有需要的依赖项创建 var 类路径条目。
使用 m2eclipse
有 Maven 容器,它定义了一个导出文件夹,对我来说是 WEB-INF/lib
。但我不想依赖 m2eclipse
所以我不再使用它。
由 eclipse:eclipse
goal 生成的类路径条目没有这样的导出文件夹。
当使用 WTP 启动 servlet 容器时,它会将除库之外的所有资源和类发布到上下文。
发布所需的库缺少什么,或者如果没有 m2eclipse 集成就不可能实现?
环境
- Eclipse 3.5 Java EE Galileo
- Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
- Java 版本:1.6.0_14
m2eclipse
maven-eclipse-plugin配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>someproject-[artifactId]</projectNameTemplate>
<useProjectReferences>false</useProjectReferences>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpmanifest>true</wtpmanifest>
<wtpversion>2.0</wtpversion>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpContextName>someproject-[artifactId]</wtpContextName>
<additionalProjectFacets>
<jst.web>2.3</jst.web>
</additionalProjectFacets>
</configuration>
</plugin>
生成的文件
执行eclipse:eclipse
目标后,依赖模块未在我生成的中列出.settings/org.eclipse.wst.common.component
,所以在服务器启动时我错过了依赖项。
这就是我得到的:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="someproject-core">
<wb-resource deploy-path="/" source-path="src/main/java"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<wb-resource deploy-path="/" source-path="src/main/resources"/>
</wb-module>
</project-modules>
为即将到来的读者更新
这里的问题是异常的打包
类型,如果你使用maven-eclipse-plugin
请验证
或 ear
的使用。
以下问题是我在一个 Maven pom 中有两个构建生命周期的情况。
I use the eclipse:eclipse
goal to generate an Eclipse Project environment. The deployment works fine. The goal creates the var classpath entries for all needed dependencies.
With m2eclipse
there was the Maven Container which defines an export folder which was WEB-INF/lib
for me. But i don't want to rely on m2eclipse
so i don't use it anymore.
the class path entries which are generated by eclipse:eclipse
goal don't have such a export folder.
While booting the servlet container with WTP it publishes all resources and classes except the libraries to the context.
Whats missing to publish the needed libs, or isn't that possible without m2eclipse integration?
Enviroment
- Eclipse 3.5 Java EE Galileo
- Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
- Java version: 1.6.0_14
m2eclipse
The maven-eclipse-plugin configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>someproject-[artifactId]</projectNameTemplate>
<useProjectReferences>false</useProjectReferences>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpmanifest>true</wtpmanifest>
<wtpversion>2.0</wtpversion>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpContextName>someproject-[artifactId]</wtpContextName>
<additionalProjectFacets>
<jst.web>2.3</jst.web>
</additionalProjectFacets>
</configuration>
</plugin>
The generated files
After executing the eclipse:eclipse
goal, the dependent-module is not listed in my generated .settings/org.eclipse.wst.common.component
, so on server booting i miss the depdencies.
This is what i get:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="someproject-core">
<wb-resource deploy-path="/" source-path="src/main/java"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<wb-resource deploy-path="/" source-path="src/main/resources"/>
</wb-module>
</project-modules>
Update for upcoming readers
The problem here was the deviant packaging
-type, if u use maven-eclipse-plugin
please validate the use of <packaging>war</packaging>
or ear
.
The following problems are marked of the situations that i have two build-lifecycles in one maven pom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定是否理解这个问题。我已经在很长一段时间内成功地将
maven-eclipse-plugin
与 maven webapps 一起使用。那么,在服务器上部署是否有效呢?该应用程序是否可用?你能澄清一下吗?为了以防万一,我用你的插件配置对一个新创建的 web 应用程序进行了快速测试,看起来没问题。我刚刚删除了
jst.java
方面并配置了maven-compiler-plugin
:并且我添加了对
log4j
的依赖项。然后,当我运行mvn eclipse:eclipse
时,这就是我在生成的.settings/org.eclipse.wst.common.component
中得到的内容:log4j
依赖项存在并被发布。我错过了什么?更新:我将提供的 pom 粘贴到我的
war
项目中,将其更改为使用 2.8 版本的 eclipse 插件,并删除了src/main/webapp
来自resources
元素(它不是资源),这是我运行mvn eclipse:eclipse
时得到的结果:对我来说看起来不错。
更新2:正如我在对您自己的答案的评论中所写的那样,我认为 Eclipse 插件不会为具有
jar
。如果您更改打包war
,它应该按预期运行。我很确定这就是你遇到麻烦的原因。I'm not sure to understand the problem. I've used the
maven-eclipse-plugin
with maven webapps during a long time with success. So, does the deployment on a Server work or not? Is the application usable or not? Can you clarify?Just in case, I did a quick test on a newly created webapp with your plugin configuration which looks ok. I just removed the
jst.java
facet and configured themaven-compiler-plugin
instead:And I added a dependency on
log4j
. Then, when I runmvn eclipse:eclipse
, this is what I get in the generated.settings/org.eclipse.wst.common.component
:The
log4j
dependency is there and gets published. What did I miss?Update: I pasted the provided pom in my
war
project, changed it to use the version 2.8 of the eclipse plugin and removedsrc/main/webapp
from theresources
element (it's not a resource) and this is what I get when runningmvn eclipse:eclipse
:Looks fine to me.
Update 2: As I wrote in a comment to your own answer, I don't think the eclipse plugin will generate a dynamic web module for a project with a packaging of type
jar
. If you change the packagingwar
, it should behave as expected. I'm pretty sure this is the cause of your troubles.示例 pom(位于 Pastie.org)
我已从其中删除了约 60 个依赖项除此之外,原始的
pom.xml
没有任何改变。您只需创建webapp-archetype
并将 pom 粘贴到生成的(通过 archetype 命令)中,此
eclipse:eclipse
会导致生成的.settings /org.eclipse.wst.common.component
现在显示project-version="2.0"
(在我从 1.0 到 1.5 和 2.0 进行了各种更改之后),但仍然是缺少<依赖模块>
。更新(@Pascal Thivent):这是一个很好的观点。我们的项目(一个网络框架)实际上有两个混合功能。有一个
jar-packaging
,它用于提供框架功能,在运行时它会将自身扩展为webapp-struct(WEB-INF/...)
但它还应该可以在 servlet 容器本身上运行该框架及其扩展,因此我们可以开发基本功能,而无需将其打包为 jar 并将其与自定义项目一起使用。所以这里的
jar
是正确的。更新2
源代码 (EclipseWtpComponentWriter)
maven-eclipse-plugin
显示这是硬编码的,除了将packaging
设置为war
之外,无法遇到 then 子句,或者我错过了什么吗? :(The example pom (on pastie.org)
I've removed ~60 dependencies from the original
pom.xml
beside this nothing changed. You just have to create thewebapp-archetype
and paste the pom into the generated (by the archetype command)After this
eclipse:eclipse
leads to the generated.settings/org.eclipse.wst.common.component
which now showsproject-version="2.0"
(after i did various changes from 1.0 to 1.5 and 2.0) but still the<dependent-module>
is missing.Update (@Pascal Thivent): This is a good point. Our project (a web-framework) has in fact two mixed features. There is the
jar-packaging
which is used to provide the framework capabilities, while running it expands itself into the webapp-structure(WEB-INF/...)
But it should also be possible to run the framework with its extensions on a servlet container itself, so we can develop the base functionality without package it as jar and use it with a custom project. So the
jar
is correct here.Update 2
The source code (EclipseWtpComponentWriter) of the
maven-eclipse-plugin
shows that this is hardcoded and there is no way to run into the then clause except setting thepackaging
towar
, or did i miss something? :(