Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Export and import of configuration files

  1. #1
    maca is offline Member
    Join Date
    Jul 2014
    Location
    UK
    Posts
    20
    Rep Power
    0

    Default Export and import of configuration files

    So, I didn't know what category to post this, so my apologies upfront if it is the wrong place. Although the context of the question is Spring, the underlying principle of what I am asking is wider than spring and could apply to anything. Anyway... as a precursory bit of information, I am using Maven as the build tool for both the library and application in the problem that I am about to describe.

    So, I have a library that I'm writing, the library contains a spring xml configuration file (lets say it's called libraryContext.xml) that sets the library up correctly for runtime, it also includes a test spring xml file that sets the library up for test by importing libraryContext.xml and overriding certain dependency injection beans (the library basically connects to a real database under normal conditions and uses dummy DAO's under test conditions). That bit is all fine.

    The thing is, when I build the jar for the library (lets say it's called library-0.1.jar), the jar does not seem to contain the libraryContext.xml and that means that I can't import library.xml into my applications context.xml.

    Basically, I have this line in my applications context.xml

    Java Code:
    <import resource = "classpath:libraryContext.xml"/>
    Unsurprisingly, since the xml file is not contained in the library-0.1.jar, the error I get is,
    Java Code:
    Offending resource: class path resource [applicationContext.xml]; 
        nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: 
            IOException parsing XML document from class path resource [libraryContext.xml]; 
                nested exception is java.io.FileNotFoundException: class path resource [libraryContext.xml] cannot be opened because it does not exist
    With respect to potential solutions to the above problem, I could:

    1) physically copy the libraryContext.xml file (and its other *.xml and *.properties dependencies) into the application, but then I'd have to maintain duplicate files - I don't like this option.
    2) find out if there is a better way to handle this problem from people who know better. :) E.g. is there a way to embed the libraryContext.xml file (and it's dependencies) into the jar file so that it can then be imported into the application. I've spent a while on google trying to figure this out and haven't come up with anything overly useful (perhaps I've been using the wrong search parameters).

    Anyway, any help would be much appreciated. :)

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Export and import of configuration files

    So where is the missing file now? Obviously it is not in a maven resources folder or it would have been packaged up by Maven.
    maca likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    maca is offline Member
    Join Date
    Jul 2014
    Location
    UK
    Posts
    20
    Rep Power
    0

    Default Re: Export and import of configuration files

    Thanks gimbal2 you are a real star, I did a search on the three key words you mention "maven resources folder", found out what to do and added the following into the pom.xml of the library
    Java Code:
            <resources>
                <resource>
                    <directory>${basedir}/src/main/config</directory>
                </resource>
            </resources>
    and now everything is working.

    Thank you once again.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Export and import of configuration files

    That works but it is basically unnecessary. Just put the file in src/main/resources which is a folder that is part of the Maven conventions and needs no configuration.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    maca is offline Member
    Join Date
    Jul 2014
    Location
    UK
    Posts
    20
    Rep Power
    0

    Default Re: Export and import of configuration files

    Ahh, I see, will do, thanks :)

Similar Threads

  1. Import and Export Files in Java
    By javalearner in forum Eclipse
    Replies: 7
    Last Post: 11-21-2013, 01:41 PM
  2. Replies: 0
    Last Post: 09-26-2011, 01:38 PM
  3. import from dsv files and export to csv files
    By 10x2 in forum New To Java
    Replies: 12
    Last Post: 04-30-2010, 11:56 AM
  4. Import / Export Issue
    By Gideonzx in forum Eclipse
    Replies: 0
    Last Post: 07-23-2009, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •