How to deal with relative path in Junits between Maven and Intellij

I have a maven project with a module

/myProject
pom.xml
    /myModule
    pom.xml
       /foo
       bar.txt

Consider a Junit in myModule which needs to open bar.txt, with maven the basedir is the module directory.

So to open the file bar.txt :

  new File("foo/bar.txt")

This works well when you execute mvn test BUT when you launch the same junit in intellij, it fails because Intellij sets the basedir in the project directory, not the module directory.

Intellij tries to open myProject/foo/bar.txt instead of myProject/myModule/foo/bar.txt

Is there a way to deal with that ?

44
задан Sean Patrick Floyd 12 April 2011 в 15:41
поделиться