Maven和Eclipse问题——寻找资源

发布于 2024-08-21 22:00:17 字数 578 浏览 4 评论 0原文

我有一个问题,maven 正在 Eclipse 安装文件夹内寻找资源。

它是说:

This file was not found: file:/C:/eclipse/eclipse/src/main/resources/config/spring/applicationContext.xml

虽然我的工作区位于 c:/Work/Core/src/main/resources 内。

pom.xml 是否有任何配置来命令它从其位置看起来是相对的?

编辑#1:

我正在从 Eclipse 运行 Maven。从命令行编译没有问题。

我正在尝试运行 Junit 测试。

编辑#2:

所有依赖项,web.xml,...都可以 - 我知道这一点是因为其他开发人员在 Linux 和 Idea 上使用相同的文件,并且项目运行没有问题。在我的项目设置中,junit 测试不起作用,编译 wsdl 文件也不起作用 - 两者都是因为它找不到资源。

编辑#3:

找到答案 - 它发布在这里。

I have a problem, that maven is looking for resources inside of Eclipse installation folder.

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.

Is there any configuration for pom.xml to order it to look relative from its position??

EDIT #1:

I am running Maven from Eclipse. From command line it compiles without problems.

I am trying to run Junit tests.

EDIT #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.

EDIT #3:

Found the answer - it is posted here down.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

别闹i 2024-08-28 22:00:18

我们还可以看到您的 web.xml 吗?使用 spring,applicationContext.xml 位置在 web.xml 中定义为:(

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>...</param-value>
</context-param>

编辑:我知道使用 maven 编译不会关心 web.xml...但是运行 jUnit 测试它可以 - 取决于如何测试已设置。)

编辑 2:从 Linux 环境切换到 Windows 环境我可以看到指定事物所在位置的问题。仅仅因为它在一种环境下运行并不意味着切换到另一种环境时不会出现问题。如果您的 Linux 开发人员决定告诉 spring applicationContext.xml 位于 /usr/local/myide/myproject/src... 该怎么办?窗户只会窒息。

Can we also see your web.xml? With spring, the applicationContext.xml location is defined in the web.xml with something like:

<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.)

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.

简单气质女生网名 2024-08-28 22:00:18

您能否将您想要执行的操作粘贴到代码或 pom.xml 的相关部分中?

理想情况下,pom.xml 中的任何目录引用都应该相对于 pom.xml 文件位置。

Can you paste what are you trying to do in the code or the relevant section of the pom.xml ?

Ideally any directory reference in pom.xml should be relative to the pom.xml file location.

深海夜未眠 2024-08-28 22:00:18

使用 Eclipse 解决 Maven 问题的一个有吸引力的方法是切换到 Netbeans。它更易于使用,并且对 Maven 项目具有本机支持。

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.

枕梦 2024-08-28 22:00:17

明白了...终于...我不知道为什么,但 Eclipse 只是不从 Maven 刷新它自己的设置。

我必须更改 .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>

在第四行中,有 except="**" - 我删除了它,它起作用了。

此后,我还遇到了项目名称的问题。在 pom.xml 中

<groupId>core-maven</groupId>
<artifactId>core-maven</artifactId>

,在构建标签 core-maven 中,我想在“core”中更改它,但它不起作用,直到我找到它并替换在 .settings 文件夹下的文件中。

Got it... Finally.. I don't know why, but Eclipse just does not refresh its own settings from Mavens.

I had to change .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.

After this, I also had problems with name of the project. In pom.xml was

<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.

物价感观 2024-08-28 22:00:17

您的配置有问题。进行一些清理并重新开始。

  • 清理你的工作空间:删除文件系统上的项目及其文件(当然首先要确保所有内容都在版本控制之下),删除现有的“Maven Build”运行配置。
  • 在文件系统上的某个位置检出您的项目(不是在工作区中,这是一个不好的做法)。
  • 将其导入 Eclipse(导入...> Maven 项目)。
  • 使用 Maven 运行测试。

PS:我假设您正在使用 m2eclipse 但这远非显而易见,您应该提供有关您的上下文的清晰信息。

You have a problem somewhere with your configuration. 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.

P.S.: I'm assuming you are using m2eclipse but this is far from obvious, you should give clear information on your context.

笑梦风尘 2024-08-28 22:00:17

几周前我也遇到了类似的问题。我更改了类路径以使内容正常工作,但这并不是真正的修复,只是一种解决方法,所以我对此不太满意。

过了一会儿,一位同事推荐了 SpringSource Tool Suite (sts)
http://www.springsource.com/products/sts

这是 SpringSource 的基于 Eclipse 的 IDE ,它有更好的 Maven 支持。自从我进行切换以来,一切都运行良好。由于它基于 Eclipse,所以我不必学习全新的 IDE,并且适用于 Eclipse 的所有内容也适用于 STS

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文