0

I have a properties file that I want my java to find but it doesn't and then I get a nullpointerexception. How can I configure maven or jetty to include my properties file? It works when I run the class from the target directory of compiled classes and the properties file is in the same directory. But when I build the project with maven and start it with jetty then the properties file is not found and I don't know where to put it since I don't know what it the directory of the running instance. Can you tell me where to put the proterties files of what to put in pom.xml to include the properties file?

        PropertiesCredentials credentials = new PropertiesCredentials(
                AWSJavaMailSample.class
                        .getResourceAsStream("AwsCredentials.properties"));
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424

1 Answers1

1

Where is the file now? It needs to be in the root of the classpath (of the classloader that loaded the AWSJavaMailSample class) to be found by getResourceAsStream() providing only the name. In standard Maven projects it should be copied if you put it into src/main/resources.

see http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

scraatz
  • 419
  • 2
  • 7
  • I've tried putting it in verious places in addition to the commoon as well as in the directory from twhich I'm running the maven plugin for jetty mvn jetty:run. I t the file in at least 4 different places but it's still not being found. – Niklas Rosencrantz Jan 18 '14 at 21:08
  • 1
    Do you have a target/classes directory in your base directory? Is the properties file in that directory after mvn compile? – scraatz Jan 18 '14 at 21:11
  • Yes and yes it is there. My problem is similar to this question: http://stackoverflow.com/questions/17949206/jetty-maven-plugin-put-properties-file-in-classpath I get a nullointerexception when trying to load the properties file, perhaps I should put it in some webapp directory? – Niklas Rosencrantz Jan 18 '14 at 21:25