Reputation: 41193
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:
Upvotes: 1
Views: 2004
Reputation: 570345
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:
- Uses /src/main/resources/keystore.jks for application code in development.
- Uses /src/test/resources/keystore.jks for test code.
- Uses /resources in the jar.
If you follow my previous advice, then you don't have anything particular to do.
src/main/resources
are available in the normal classpathsrc/test/resources
are available in the test classpath (which has precedence on the normal classpath when runnign mvn test
)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.
Upvotes: 3