views:

656

answers:

6

Hello!

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.

A: 

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.

Calm Storm
+1  A: 

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.

Quotidian
I knew that there would be problems :) I can not find a solution... I just think, that there is no problem with pom.xml and web.xml.
Trick
This doesn't have anything to do with unit testing though.
Pascal Thivent
It does have things to do with unit testing if one is attempting to initialize the spring webApplicationContext in the tests. Spring has specialized methods for testing such as SpringJUnit4ClassRunner.class
Quotidian
+1  A: 

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.

Pascal Thivent
I guess this is the only thing felt... Will try now.
Trick
A: 

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.

Daniel
Oh... Netbeans... Five or six years ago, it was a very bad IDE... Is it any better now? In this spirit I could switch to IDEA, because I know it works there.
Trick
From what I understand, Netbeans has improved considerably since then (particularly in terms of its performance). Its clean integration with Maven is the reason I've switched from Eclipse for most projects.
Daniel
It's irrelevant. The question is about Eclipse and should be answered as such
DroidIn.net
Looks like the OP disagreed with you on that, judging by the comment above ;)
Daniel
+1  A: 

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.

Trick
Yep - thanks a bunch, this did it!
DroidIn.net
+1  A: 

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

Jonas Söderström
+1 In finding for solution I have also found this IDE. I am planning to test it in near future. Thanks for the info!
Trick