Below you find the actual code I use. In order to get the error, you just need a JUnit testCase that constructs the PropertyReader class. Note that I can not change the line ClassLoader.getSystemResourceAsStream(" log.properties"); as it's part of a library we use. The file log.properties is present in the directory src/test/resources.
package test.surefire; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertyReader { private Properties systemLogProps; public PropertyReader() throws IOException { this.systemLogProps = new Properties(); InputStream is = ClassLoader.getSystemResourceAsStream(" log.properties"); // the following works // InputStream is = this.getClass ().getClassLoader().getResourceAsStream("log.properties"); if (is == null) { throw new RuntimeException("log.properties not found on the classpath"); } this.systemLogProps.load(is); } public String getProperty(String key) { return this.systemLogProps.getProperty(key); } } So the problem is that the file log.properties can not be found on the system classpath. Any help is appreciated. On 7/1/07, Andrew Williams <[EMAIL PROTECTED]> wrote:
Perhaps posting the actual code will help. When it comes to classloading many loaders such as eclipse are very liberal whereas the surefire loader is more strict to the java spec. Andy On 27 Jun 2007, at 14:05, Erik Ruisma wrote: > Hello, > > I've been trying out several options on the maven-surefire-plugin > (useSystemClassLoader, forkMode, childDelegation), but without any > succes. > > We have some library that does a > ClassLoader.getSystemResourceAsStream in > order to read a property file. > I've added that property file under src/test/resources but 'Maven' > is unable > to find it (seems to have to do with the IsolatedClassLoader). > I can not change the getSystemResourceAsStream, as mentioned > several times > in this forum into something like this.getClass > ().getClassLoader().getResourceAsStream(... > > I'm not quite sure what useSystemClassLoader is meant to do > exactly. If I > try to use it I get the following error: > > [INFO] Building jar: C:\DOCUME~1\mfr\LOCALS~1\Temp > \surefirebooter58425.jar > Forking command line: C:\javadev\tools\java\sdk\1.4.2_04\jre\bin > \java -jar > C:\DOCUME~1\mfr\LOCALS~1\Temp\surefirebooter58425.jar > C:\DOCUME~1\mfr\LOCALS~1\Temp\surefire58423tmp > C:\DOCUME~1\mfr\LOCALS~1\Temp\surefire58424tmp > java.lang.NoClassDefFoundError: org/apache/maven/surefire/booter/ > SurefireBooter > Exception in thread "main" > > > Any clue on how to solve this error, or on how to get the > getSystemResourceAsStream method working with Maven ? > > > Thanks in advance ! --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]