Maven 和 Eclipse 问题——寻找资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2273009/
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 and Eclipse problem - looking for resources
提问by Trick
I have a problem, that maven is looking for resources inside of Eclipse installation folder.
我有一个问题,maven 正在 Eclipse 安装文件夹中寻找资源。
It is saying:
它在说:
This file was not found: file:/C:/eclipse/eclipse/src/main/resources/config/spring/applicationContext.xml
While my workspace is in c:/Work/Core/
and inside src/main/resources
.
虽然我的工作区c:/Work/Core/
在src/main/resources
.
Is there any configuration for pom.xml to order it to look relative from its position??
pom.xml 是否有任何配置来命令它从它的位置看起来是相对的??
EDIT #1:
编辑#1:
I am running Maven from Eclipse. From command line it compiles without problems.
我正在从 Eclipse 运行 Maven。从命令行它编译没有问题。
I am trying to run Junit tests.
我正在尝试运行 Junit 测试。
EDIT #2:
编辑#2:
All dependencies, web.xml,... are OK - I know this because the same files other developer is using on Linux and with Idea and there the project is working without problems. With my project settings junit tests are not working, compiling wsdl files is not working - both because it can not find resources.
所有依赖项,web.xml,...都可以 - 我知道这是因为其他开发人员在 Linux 和 Idea 上使用的文件相同,并且项目在那里工作没有问题。由于我的项目设置 junit 测试不起作用,因此编译 wsdl 文件不起作用 - 两者都是因为它找不到资源。
EDIT #3:
编辑#3:
Found the answer - it is posted here down.
找到了答案 - 它发布在这里。
回答by Trick
Got it... Finally.. I don't know why, but Eclipse just does not refresh its own settings from Mavens.
明白了……最后……我不知道为什么,但 Eclipse 只是没有从 Maven 刷新它自己的设置。
I had to change .classpath:
我不得不改变 .classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
In the fourth line, there excluding="**"
- I removed this, and it worked.
在第四行,那里excluding="**"
- 我删除了它,它起作用了。
After this, I also had problems with name of the project. In pom.xml was
在此之后,我也遇到了项目名称的问题。在 pom.xml 是
<groupId>core-maven</groupId>
<artifactId>core-maven</artifactId>
and in build tag <finalName>core-maven</finalName>
which I wanted to change in just "core", but it did not work, until I found it and replace in files under .settings folder.
在构建标记中<finalName>core-maven</finalName>
,我只想在“核心”中更改它,但它不起作用,直到我找到它并在 .settings 文件夹下的文件中替换它。
回答by Quotidian
Can we also see your web.xml? With spring, the applicationContext.xml location is defined in the web.xml with something like:
我们也可以看看你的 web.xml 吗?使用 spring,applicationContext.xml 位置在 web.xml 中定义,如下所示:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>...</param-value>
</context-param>
(EDIT: I know compiling with maven won't care about the web.xml... but running jUnit tests it could - depending on how the tests are set up.)
(编辑:我知道用 maven 编译不会关心 web.xml ......但它可以运行 jUnit 测试 - 取决于测试的设置方式。)
EDIT 2: Switching from a linux environment to a windows environment I could see problems with specifying where things live. Just because it runs under one environment doesn't mean there won't be problems when switching to another. What if your linux dev decided to tell spring the applicationContext.xml lives at /usr/local/myide/myproject/src...? Windows would just choke.
编辑 2:从 linux 环境切换到 windows 环境我可以看到指定事物所在位置的问题。仅仅因为它在一种环境下运行并不意味着切换到另一种环境时不会出现问题。如果您的 linux 开发人员决定告诉 spring applicationContext.xml 位于 /usr/local/myide/myproject/src... 怎么办?Windows 会窒息。
回答by Pascal Thivent
You have a problem somewhere with yourconfiguration. Do some cleanup and start again.
您的配置有问题。做一些清理工作,然后重新开始。
- Clean your workspace: delete the project and its files on the file system (make sure everything is under version control first of course), delete existing "Maven Build"Run Configurations.
- Checkout your project somewhere on your file system (not in the workspace, this is a bad practice).
- Import it in Eclipse (Import... > Maven Projects).
- Run your tests with Maven.
- 清理您的工作区:删除文件系统上的项目及其文件(当然首先确保所有内容都在版本控制之下),删除现有的“Maven Build”运行配置。
- 在文件系统的某个地方签出您的项目(不在工作区中,这是一种不好的做法)。
- 在 Eclipse 中导入它(Import... > Maven Projects)。
- 使用 Maven 运行您的测试。
P.S.: I'm assuming you are using m2eclipse but this is far from obvious, you should give clear information on your context.
PS:我假设您正在使用 m2eclipse 但这远非显而易见,您应该提供有关您的上下文的明确信息。
回答by Jonas S?derstr?m
I had similar problems a few weeks ago. I changed the classpath to get stuff to work but that is not really a fix, only a workaround, so I wasn't very happy about it.
几周前我遇到了类似的问题。我更改了类路径以使内容正常工作,但这并不是真正的修复,只是一种解决方法,所以我对此不太满意。
After a while a colleague recommended SpringSource Tool Suite (sts) http://www.springsource.com/products/sts
过了一会儿同事推荐了SpringSource Tool Suite (sts) http://www.springsource.com/products/sts
It's a Eclipse based IDE by SpringSource, it has much better Maven support. Since I made the switch everything works great. And since it is based on Eclipse I didn't have to learn a whole new IDE and everything that works for Eclipse works for STS
它是 SpringSource 基于 Eclipse 的 IDE,它有更好的 Maven 支持。因为我做了开关,所以一切都很好。因为它基于 Eclipse,所以我不必学习一个全新的 IDE,所有适用于 Eclipse 的东西都适用于 STS
回答by Kannan Ekanath
Can you paste what are you trying to do in the code or the relevant section of the pom.xml ?
你能在代码或 pom.xml 的相关部分粘贴你想要做什么吗?
Ideally any directory reference in pom.xml should be relative to the pom.xml file location.
理想情况下,pom.xml 中的任何目录引用都应与 pom.xml 文件位置相关。
回答by Daniel
An attractive way to solve Maven problems with Eclipse is to switch to Netbeans. It's easier to use, and has native support for Maven projects.
使用 Eclipse 解决 Maven 问题的一个有吸引力的方法是切换到 Netbeans。它更易于使用,并且对 Maven 项目具有本机支持。