带有 maven-eclipse-plugin 的 Maven webapp 不会生成 <dependent-module>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2713648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven webapp with maven-eclipse-plugin doesn't generate <dependent-module>
提问by Christopher Klewes
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.
我使用eclipse:eclipse
目标来生成一个 Eclipse 项目环境。部署工作正常。目标为所有需要的依赖项创建 var 类路径条目。
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.
随着m2eclipse
有Maven的容器,它定义这是一个导出文件夹WEB-INF/lib
给我。但我不想依赖m2eclipse
所以我不再使用它了。
the class path entries which are generated by eclipse:eclipse
goal don't have such a export folder.
由eclipse:eclipse
目标生成的类路径条目没有这样的导出文件夹。
While booting the servlet container with WTP it publishes all resources and classes except the libraries to the context.
在使用 WTP 启动 servlet 容器时,它将除库之外的所有资源和类发布到上下文中。
Whats missing to publish the needed libs, or isn't that possible without m2eclipse integration?
发布所需的库缺少什么,或者如果没有 m2eclipse 集成是不可能的?
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
- Eclipse 3.5 Java EE 伽利略
- Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
- Java 版本:1.6.0_14
日食
The maven-eclipse-plugin configuration
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>
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.
执行eclipse:eclipse
目标后,依赖模块未在我的生成中列出.settings/org.eclipse.wst.common.component
,因此在服务器启动时我错过了依赖项。
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
.
这里的问题是异常packaging
类型,如果你使用maven-eclipse-plugin
请验证使用<packaging>war</packaging>
or ear
。
The following problems are marked of the situations that i have two build-lifecycles in one maven pom.
以下问题标记了我在一个 maven pom 中有两个构建生命周期的情况。
采纳答案by Pascal Thivent
Whats missing to publish the needed libs, or isn't that possible without m2eclipse integration?
发布所需的库缺少什么,或者如果没有 m2eclipse 集成是不可能的?
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?
我不确定是否理解这个问题。我maven-eclipse-plugin
在很长一段时间内成功地使用了maven webapps。那么,在服务器上部署是否有效?应用程序是否可用?你能澄清一下吗?
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 the maven-compiler-plugin
instead:
以防万一,我使用您的插件配置对新创建的 webapp 进行了快速测试,看起来不错。我只是删除了jst.java
方面并配置了maven-compiler-plugin
:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
<source>1.5</source>
</configuration>
</plugin>
And I added a dependency on log4j
. Then, when I run mvn eclipse:eclipse
, this is what I get in the generated .settings/org.eclipse.wst.common.component
:
我添加了对log4j
. 然后,当我运行时mvn eclipse:eclipse
,这就是我在生成的.settings/org.eclipse.wst.common.component
:
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="example-mvn-Q2713648">
<property name="context-root" value="example-mvn-[artifactId]"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<property name="java-output-path" value="/target/classes"/>
<dependent-module archiveName="log4j-1.2.14.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
</wb-module>
</project-modules>
The log4j
dependency is there and gets published. What did I miss?
该log4j
相关性是存在的,并得到出版。我错过了什么?
Update:I pasted the provided pom in my war
project, changed it to use the version 2.8 of the eclipse plugin and removed src/main/webapp
from the resources
element (it's not a resource) and this is what I get when running mvn eclipse:eclipse
:
更新:我在我的war
项目中粘贴了提供的 pom ,将其更改为使用 eclipse 插件的 2.8 版并src/main/webapp
从resources
元素中删除(它不是资源),这就是我在运行时得到的结果mvn eclipse:eclipse
:
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="example-mvn-Q2713648">
<property name="context-root" value="example-mvn-[artifactId]"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<property name="java-output-path" value="/target/classes"/>
<dependent-module archiveName="hsqldb-1.8.0.10.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/hsqldb/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
</wb-module>
</project-modules>
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 packaging war
, it should behave as expected. I'm pretty sure this is the cause of your troubles.
更新 2:正如我在对您自己的答案的评论中所写的那样,我认为 eclipse 插件不会为打包类型为 的项目生成动态 Web 模块jar
。如果您更改包装war
,它应该按预期运行。我很确定这就是您遇到麻烦的原因。
回答by Christopher Klewes
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 the webapp-archetype
and paste the pom into the generated (by the archetype command)
我已经从原始版本中删除了大约 60 个依赖项,pom.xml
除此之外没有任何改变。您只需要创建webapp-archetype
pom 并将其粘贴到生成的(通过原型命令)
mvn archetype:create
-DgroupId=example
-DartifactId=mvn
-DarchetypeArtifactId=maven-archetype-webapp
After this eclipse:eclipse
leads to the generated .settings/org.eclipse.wst.common.component
which now shows project-version="2.0"
(after i did various changes from 1.0 to 1.5 and 2.0) but still the <dependent-module>
is missing.
在这之后eclipse:eclipse
导致.settings/org.eclipse.wst.common.component
现在显示的生成project-version="2.0"
(在我做了从 1.0 到 1.5 和 2.0 的各种更改之后)但仍然<dependent-module>
丢失。
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="example-mvn-mvn">
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<wb-resource deploy-path="/" source-path="src/main/resources"/>
</wb-module>
</project-modules>
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/...)
更新 (@Pascal Thivent):这是一个很好的观点。我们的项目(一个网络框架)实际上有两个混合功能。有jar-packaging
用于提供框架功能的,在运行时将自身扩展到 webapp 结构中(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.
但是也应该可以在 servlet 容器本身上运行带有扩展的框架,因此我们可以开发基本功能,而无需将其打包为 jar 并将其与自定义项目一起使用。所以jar
这里是正确的。
Update 2
更新 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 the packaging
to war
, or did i miss something? :(
该源代码(EclipseWtpComponentWriter)中的maven-eclipse-plugin
表演,这是硬编码,也没有办法运行到当时的条款,除了设置packaging
到war
,或我错过了什么?:(
private void writeModuleTypeComponent( XMLWriter writer, String packaging,
File buildOutputDirectory, EclipseSourceDir[] sourceDirs,
ArtifactRepository localRepository)
{
if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ))
{
// Adding the <dependent-modules> stuff
}
}