Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceHolderConfigurration classpath not recognized running jar in batch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceHolderConfigurration classpath not recognized running jar in batch

    Hi,

    This problem might have occurred already but am not able to find out a solution for this.

    I'm using spring PropertyPlaceHolderConfigurration to get the file from classpath.
    A. spring file
    Code:
    <bean
    		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location" value="classpath:abc.properties"/>.
    .
    </bean>
    This property file is something, that i want user to have access so that he modify and point to any required location. As a separate maven project it works fine as it exists within my classpath. I'm using Maven to package the whole project and not to include this property within resultant .jar file. Till this point everything is fine.

    Now the problem is:
    I have placed above .jar file and required dependency within lib, and abc.properties file under config directory. I'm trying to run that executable jar file using bat which is in bin directory. Pretty simple structure :-) within bin directory, i have below batch file
    B. batch file
    Code:
    set PATH=C:\Program Files\Java\jdk1.7.0_10\bin;%PATH%
    
    set lib=..\lib
    
    set cp=
    set cp=%cp%;..\config
    
    java -version
    java -cp %cp% -jar ..\lib\MyProject_SNAPSHOT.jar %*
    abc.properties file in under config directory, and MyProject_SNAPSHOT.jar contains spring xml file as mentioned above in A. When i run this batch file.... i always get error as
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanInitializationE
    xception: Could not load properties; nested exception is java.io.FileNotFoundExc
    eption: class path resource [abc.properties] cannot be opened because i
    t does not exist
            at org.springframework.beans.factory.config.PropertyResourceConfigurer.p
    ostProcessBeanFactory(PropertyResourceConfigurer.java:87)
            at org.springframework.context.support.AbstractApplicationContext.invoke
    BeanFactoryPostProcessors(AbstractApplicationContext.java:694)
            at org.springframework.context.support.AbstractApplicationContext.invoke
    BeanFactoryPostProcessors(AbstractApplicationContext.java:669)
            at org.springframework.context.support.AbstractApplicationContext.refres
    h(AbstractApplicationContext.java:461)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:83)
            at com.reuters.mockpts.Main.main(Main.java:42)
    Caused by: java.io.FileNotFoundException: class path resource [mqconnection.prop
    erties] cannot be opened because it does not exist
            at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat
    hResource.java:157)
            at org.springframework.core.io.support.EncodedResource.getInputStream(En
    codedResource.java:143)
            at org.springframework.core.io.support.PropertiesLoaderUtils.fillPropert
    ies(PropertiesLoaderUtils.java:98)
            at org.springframework.core.io.support.PropertiesLoaderSupport.loadPrope
    rties(PropertiesLoaderSupport.java:175)
            at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProp
    erties(PropertiesLoaderSupport.java:156)
            at org.springframework.beans.factory.config.PropertyResourceConfigurer.p
    ostProcessBeanFactory(PropertyResourceConfigurer.java:78)
            ... 6 more
    I guess for some reason, spring classpath is using totally different classpath and trying to find this properties file within same MyProject_SNAPSHOT.jar which is obviously not placed there ( like explained it should have user control)

    can you please guide me for this problem? If you need more information please let me know.

    Thanks

  • #2
    Why not simply use file: instead of classpath: and point it to the correct location?!

    There is also a difference between classpath: and classpath*:

    Comment


    • #3
      Yes, at the end that's what i have done.

      But i raised this more like to understand the 'classpath' feature used for PropertyPlaceholderConfigurer. As ideally if am mentioning within .xml file that get it from classpath and within batch by writing

      set cp=%cp%;..\config

      should be *in theory* placing on the same JVM's classpath and xml PropertyPlaceholderConfigurer should recognize the property file as that was also looking onto classpath . Or am i missing something here??

      Comment

      Working...
      X