tags:

views:

179

answers:

1

I have a keystore file that I want available to several classes in my application. I made a .config file that points the name of the keystore file, it's password, and other information.

It's a Maven-based project, so the keystore is in /src/main/resources. I build a jar and move the file to /resources in the jar. I'd like the .config file to say something like "resources/keystore.jks".

How do I parse the .config file so it:

  1. Uses /src/main/resources/keystore.jks for application code in development.
  2. Uses /src/test/resources/keystore.jks for test code.
  3. Uses /resources in the jar.
+2  A: 

It's a Maven-based project, so the keystore is in /src/main/resources. I build a jar and move the file to /resources in the jar. I'd like the .config file to say something like "resources/keystore.jks".

Why do you do that? You shouldn't have to move it. Just put that keystore in resources/resources/keystore.jks if you want it to be available in /resources on the classpath.

How do I parse the .config file so it:

  1. Uses /src/main/resources/keystore.jks for application code in development.
  2. Uses /src/test/resources/keystore.jks for test code.
  3. Uses /resources in the jar.

If you follow my previous advice, then you don't have anything particular to do.

  1. Resources in src/main/resources are available in the normal classpath
  2. Resources in src/test/resources are available in the test classpath (which has precedence on the normal classpath when runnign mvn test)
  3. src/main/resources is the root of the resource path. If you want something to be available under /my/package/my.properties, then put in src/main/resources/my/package/my.properties.

If really this doesn't cover your needs, then have a look at resources filtering. Filtering can be combined with profiles for more complicated things. Or you could also use several filters and pick up the right one by passing a property. But, as I said, I'm not sure you need this.

Pascal Thivent