在 Maven 项目中更新 .settings/org.eclipse.wst.common.component 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2048719/
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
Updating .settings/org.eclipse.wst.common.component file in a maven project
提问by Ger
I working with a maven project in eclipse and am having trouble with getting the deployment to work without some manual editing of xml files.
我在 Eclipse 中使用了一个 Maven 项目,并且在没有手动编辑 xml 文件的情况下无法使部署工作。
When I build the project through maven I get a org.eclipse.wst.common.component xml file in my .settings folder. The file looks like the following:
当我通过 maven 构建项目时,我在 .settings 文件夹中得到一个 org.eclipse.wst.common.component xml 文件。该文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="ins-web">
<wb-resource deploy-path="/" source-path="/WebContent"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/java"/>
<property name="context-root" value="ins-web"/>
<property name="java-output-path"/>
</wb-module>
</project-modules>
The following line is causing the problem:
以下行导致了问题:
<wb-resource deploy-path="/" source-path="/WebContent"/>
Its looking to deploy everything below the WebContent folder when really it should be looking in src/webapp. The line should therefore look like this:
它希望在 WebContent 文件夹下部署所有内容,而实际上它应该在 src/webapp 中查找。因此,该行应如下所示:
<wb-resource deploy-path="/" source-path="/src/webapp"/>
If I change it manually then it all works fine but I'd like to know if there is a way to avoid manually changing the file to make the build process easier for other people on my team.
如果我手动更改它,那么它一切正常,但我想知道是否有办法避免手动更改文件以使我团队中的其他人更容易构建过程。
回答by Peter Lynch
How are you generating your eclipse files. Are you using the m2eclipse Eclipse pluginor are your using the maven-eclipse-plugin? m2eclipse is a plugin for Eclipse, run inside Eclipse. the maven-eclipse-plugin is a Maven plugin run from the cmd line to generate Eclipse project files based on your pom.xml.
你是如何生成你的 eclipse 文件的。您是使用m2eclipse Eclipse 插件还是使用maven-eclipse-plugin?m2eclipse 是 Eclipse 的插件,在 Eclipse 中运行。maven-eclipse-plugin 是一个从 cmd 行运行的 Maven 插件,用于根据您的 pom.xml 生成 Eclipse 项目文件。
I have always had better success using the maven-eclipse-plugin. The authors of m2eclipse do not suggest you try to use both plugins together.
我一直使用 maven-eclipse-plugin 取得了更好的成功。m2eclipse 的作者不建议您尝试同时使用这两个插件。
If you are using the maven-eclipse-plugin, you should check a couple of things.
如果您使用的是 maven-eclipse-plugin,您应该检查几件事。
- Use the latest maven-eclipse-plugin version 2.7.
- Make sure your project is a 'war' packaging'
- Configure the maven-war-plugin as well and set the war source directory as you see fit. Add the following snippet to your pom.xml. This is how the maven-eclipse-plugin determines where your webapp lives.
- 使用最新的 maven-eclipse-plugin 版本 2.7。
- 确保您的项目是“War”包装
- 还要配置 maven-war-plugin 并根据需要设置 war 源目录。将以下代码段添加到您的 pom.xml。这就是 maven-eclipse-plugin 如何确定您的 web 应用程序所在的位置。
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <warSourceDirectory>src/webapp</warSourceDirectory> </configuration> </plugin>
After making these changes and running mvn eclipse:clean eclipse:eclipse
again, you should see the expected value in your component file.
进行这些更改并mvn eclipse:clean eclipse:eclipse
再次运行后,您应该会在组件文件中看到预期值。
回答by James Gustard
In maven-eclipse-plugin config add...
在 maven-eclipse-plugin 配置中添加...
<additionalConfig>
<file>
<name>.settings/org.eclipse.wst.common.component</name>
<content>
<![CDATA[Your file content here
]]>
</content>
</file>
</additionalConfig>
回答by user2501256
Well, to regenerate the file for JAR (only), on the project, right click > Properties > Project Facets: - Check the Java option and choose the Java version. It will generate the file org.eclipse.wst.common.project.facet.coreinto the .settingsfolder - Check the Utility Module. It will generate the file org.eclipse.wst.common.componentinto the .settingsfolder - Click on Apply button and/or OK button
好吧,要重新生成 JAR 文件(仅),在项目上,右键单击 > 属性 > 项目构面: - 检查 Java 选项并选择 Java 版本。它将在.settings文件夹中生成文件org.eclipse.wst.common.project.facet.core- 检查实用程序模块。它将在.settings文件夹中生成文件org.eclipse.wst.common.component- 单击 Apply 按钮和/或 OK 按钮
This is only a way to generate the file for your IDE environment. From our understanding, one reason of why m2e-wtp does not generate correctly the file is a "bad" POM. It seems that the Project Facets are deduced from the pom.xml file and their relationships between other projects/modules (ex.: Dependencies with a web module/Java EE project type).
这只是为您的 IDE 环境生成文件的一种方法。根据我们的理解,m2e-wtp 无法正确生成文件的一个原因是“坏”的 POM。似乎项目方面是从 pom.xml 文件及其其他项目/模块之间的关系推导出来的(例如:具有 Web 模块/Java EE 项目类型的依赖项)。