java - Incorrect file path being used within submodule -


a multi-module project works colleagues fails me. problem arises during test references file , in spring configuration files when reference file. reference never includes sub module folder name, or full file paths don't resolved correctly.

for example parentproject parent , childproject sub module.

parentproject     - childproject         - src/test/java/my/package/mytest.java         - src/test/resources             - xml/myfile.xml             - myproperties.properties             - myspringconfig.xml 

if have following in mytest.java:

file file = new file("src/test/resources/xml/myfile.xml"); string absolutepath = file.getabsolutepath(); 

then absolutepath c:\parentproject\src\test\resources\xml\myfile.xml incorrect it's missing childproject folder , throws filenotfoundexception.

getting same issue mention of properties files in spring configuration files e.g. in myspringconfig.xml have line:

<context:property-placeholder location="classpath:myproperties.properties" system-properties-mode="override"/> 

however on trying build project get:

illegalstateexception: failed load applicationcontext caused by: org.springframework.beans.factory.beaninitializationexception: not load properties; nested exception java.io.filenotfoundexception: src\test\resources\myproperties.properties (the system cannot find path specified) 

i feeling it's classpath issue. have maven 3.0.3 set , working installed java version (verified mvn -version). , both java , javac versions correct command line.

any ideas?

added full -x output debugging:

[25/04/13 13:45:21:812 bst] [main] error org.springframework.test.context.testcontextmanager: caught exception while allowing testexecutionlistener [org.springframework.test.context.support.dependencyinjectiontestexecutionlistener@a166bd] prepare test instance [my.package.mytest@60029d] java.lang.illegalstateexception: failed load applicationcontext         @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:308)         @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.injectdependencies(dependencyinjectiontestexecutionlistener.java:109)         @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.preparetestinstance(dependencyinjectiontestexecutionlistener.java:75)         @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:321)         @ org.springframework.test.context.junit4.springjunit4classrunner.createtest(springjunit4classrunner.java:220)         @ org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall(springjunit4classrunner.java:301)         @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15)         @ org.springframework.test.context.junit4.springjunit4classrunner.methodblock(springjunit4classrunner.java:303)         @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:240)         @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:47)         @ org.junit.runners.parentrunner$3.run(parentrunner.java:231)         @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:60)         @ org.junit.runners.parentrunner.runchildren(parentrunner.java:229)         @ org.junit.runners.parentrunner.access$000(parentrunner.java:50)         @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:222)         @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:28)         @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61)         @ org.junit.internal.runners.statements.runafters.evaluate(runafters.java:30)         @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:70)         @ org.junit.runners.parentrunner.run(parentrunner.java:300)         @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:180)         @ org.apache.maven.surefire.junit4.junit4testset.execute(junit4testset.java:35)         @ org.apache.maven.surefire.junit4.junit4provider.executetestset(junit4provider.java:115)         @ org.apache.maven.surefire.junit4.junit4provider.invoke(junit4provider.java:97)         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)         @ java.lang.reflect.method.invoke(method.java:597)         @ org.apache.maven.surefire.booter.providerfactory$classloaderproxy.invoke(providerfactory.java:103)         @ $proxy0.invoke(unknown source)         @ org.apache.maven.surefire.booter.surefirestarter.invokeprovider(surefirestarter.java:150)         @ org.apache.maven.surefire.booter.surefirestarter.runsuitesinprocess(surefirestarter.java:91)         @ org.apache.maven.surefire.booter.forkedbooter.main(forkedbooter.java:69) caused by: org.springframework.beans.factory.beaninitializationexception: not load properties; nested exception java.io.filenotfoundexception: src\test\resources\myproperties.properties (the system cannot find path specified)         @ org.springframework.beans.factory.config.propertyresourceconfigurer.postprocessbeanfactory(propertyresourceconfigurer.java:78)         @ org.springframework.context.support.abstractapplicationcontext.invokebeanfactorypostprocessors(abstractapplicationcontext.java:663)         @ org.springframework.context.support.abstractapplicationcontext.invokebeanfactorypostprocessors(abstractapplicationcontext.java:638)         @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:407)         @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:84)         @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:1)         @ org.springframework.test.context.testcontext.loadapplicationcontext(testcontext.java:280)         @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:304)         ... 32 more caused by: java.io.filenotfoundexception: src\test\resources\myproperties.properties (the system cannot find path specified)         @ java.io.fileinputstream.open(native method)         @ java.io.fileinputstream.<init>(fileinputstream.java:106)         @ java.io.fileinputstream.<init>(fileinputstream.java:66)         @ sun.net.www.protocol.file.fileurlconnection.connect(fileurlconnection.java:70)         @ sun.net.www.protocol.file.fileurlconnection.getinputstream(fileurlconnection.java:161)         @ org.springframework.core.io.urlresource.getinputstream(urlresource.java:124)         @ org.springframework.core.io.support.propertiesloadersupport.loadproperties(propertiesloadersupport.java:181)         @ org.springframework.core.io.support.propertiesloadersupport.mergeproperties(propertiesloadersupport.java:161)         @ org.springframework.beans.factory.config.propertyresourceconfigurer.postprocessbeanfactory(propertyresourceconfigurer.java:69)         ... 39 more 

the code in examples correct; maven changes subdirectories builds project, problem must elsewhere.

when absolutepath, can see doesn't happen. it's if "someone" trying execute code module childproject parentproject.

to find out happens, can try run maven -x turn on debugging. make sure childproject correctly referenced in parent pom using module element.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -