i've been looking @ questions related spring propertyplaceholderconfigurer
beans , associated classpaths, far have been unable resolve issue. i'm doing changes older program called myapp
, runs jar , has external properties file called myapp.properties' file, lives in directory called 'config' within application directory. in the
applicationcontext.xml' file `myapp' have bean defined read in external properties file:
<bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="locations"> <list> <value>classpath:myapp.properties</value> </list> </property>
this application works fine when built , run within netbeans, because include config
folder along jar dependencies builds , runs. when try run command line using java -jar myapp.jar
, following error:
08/01/2016 15:37:18.562 | error | unable start application. | org.springframework.beans.factory.beaninitializationexception: not load properties; nested exception java.io.filenotfoundexception: class path resource [myapp.properties] cannot opened because not exist
i need specify classpath correctly spring knows find properties file, i'm not sure how so, pointers appreciated...
what worked me this:
java -cp "myapp.jar;lib/*;config" com.mycompany.myapp.main
(yes, class main() method called main. no, didn't write program :) )
my classpath specifies jar contains main class, directory lib
containing other jars needed run application (using '*' character avoid having write out name of every jar in directory), , 'config' directory contains various configuration files. figured out specify myapp.properties
without qualifiers in property-configurer definition, allowing me keep file in same directory 'myapp.jar' without issue.
Comments
Post a Comment