I'm trying to import part of my spring context from external file. at the bottom of my spring xml I have:

<import resource="${file}" />

I want to specify ${file} using command line argument and I use JVM properties for that. I'm making an executable jar using maven assembly plugin.

Then I run it and I specify a file with JVM parameter:

java -jar [app.jar] -Dfile=model-a.xml

This works fine when I debug using eclipse.

But when I pack my file using maven spring cannot resolve the path and for some reason it tries to locate the file in "spring/model-a.xml" I build my jar using maven-assembly-plugin.

Why running using java -jar adds "spring/" to my path ?

有帮助吗?

解决方案

This was solved after changing the spring configuration to:

<import resource="file:${file}" />

And using java -jar [jar] -Dfile=realpath model-a.xml

其他提示

Look at the copy of the file in target/classes; you will probably find that ${file} is gone and has been replaced with model-a.

To fix this, I suggest to use a longer name for the variable, preferably one which tells other people what the meaning for this could be.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top