• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Reading applicationContext file from META-INF in spring apps  RSS feed

 
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ALL,

I am trying to read applicationContext file from META-INF because i am creating the jar of my project APIs.
When i am trying to read it in my project(simple java project) normally e.g. in resource/applicationContext.xml then able to read it fine and loads successfully.
But once i create the lib of it and putting this spring context file in META-INF then its not reading the file...
i tried

ClassPathXMLApplicationContext("META-INF/applicationContext.xml")

and also

getClass().getClassLoader().getResourceAsStream("META-INF/applicationContext.xml")

.
But not able to create the bean, which i am able to read, load and create normally...

Please provide me proper solution of it.

Thanks...
 
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I am following you. In your jar project you would put the config XML in src/main/resources. Then you are building that jar. Now you are including that jar as a dependency in another jar. Where is the META-INF stuff coming from? If both your projects have their own configs in src/main/resources and they have the same name i.e. applicationContext.xml you need to do something like this


This special prefix specifies that all classpath resources that match the given name must be obtained
 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks 4 your reply Bill,

Actually when i am creating the archive(jar) of my classes (ofcourse it i'll have META-INF) at that time i am putting this config (xml etc.) file from /resource/.. to META-INF folder of the jar.
But but not able to read it from META-INF folder.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I don't understand is why you are moving it. The classpath: prefix will look inside jars.
 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What I don't understand is why you are moving it. The classpath: prefix will look inside jars.



can you please tell me where exactly i have to use this...when i create the library of my apis or before i.e. when i am developing it in eclipse or will it work in both the scenarios ?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should work in both.

You have in JAR1

src/main/resources/jar1-application-context.xml


You have in JAR2
src/main/resources/jar2-application-context-xml



Now JAR2 has a dependency on JAR1. JAR1 is on the classpath. When I start JAR2

 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this but not working, its giving exception on reading the file.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of exception? If its a file not found then that means the jar is not on the classpath.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Form Apache Tomcat i think with default classpath point to "...webapp/WEB-INF/classes/" use debug mode.

So if you realy want file from folder "META-INF" try this.

InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "../../META-INF/" + fileName);
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!