-
1. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
jaikiran Nov 19, 2011 3:52 AM (in response to nick.sree)You'll have to provide more details including relevant code. Where are you trying to use this construct and what do you mean by "want to get .jar"?
-
2. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 19, 2011 5:11 AM (in response to jaikiran)File mappingJar = new File(Thread.currentThread().getContextClassLoader().getResource("mappings.jar").getFile());
this was the piece of code we were using to get the jar file, but in JBoss AS 7 its not working its giving null even the mappings.jar exist. our project structure is like follows
xyz.ear--|
|-- abc.war
|--lib--|
|
|--mappings.jar
|--abcjava.jar
I'm trying to call the above mentioned method from a class belongs to abcjava.jar but when i debugged the following line of code
Thread.currentThread().getContextClassLoader().getResource("mappings.jar")
its coming back as null.
I hope this would be enough to understand the problem, please let me know if u need more specification
thanks
Nick
-
3. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 22, 2011 12:21 AM (in response to nick.sree)Any idea please ?
-
4. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
sfcoy Nov 23, 2011 12:37 AM (in response to nick.sree)I don't think "mappings.jar" is a resource in this context. On the other hand, it's content (if that's what you're looking for) could be.
-
5. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 23, 2011 2:38 AM (in response to sfcoy)Yes absolutly that jar contains all hibernate mapping xml files which i want to pass it to Hibernate configuration like below.
final Configuration configuration = new Configuration();
File mappingJarsLocation = new File(Thread.currentThread().getContextClassLoader().getResource("mappings.jar").getFile());
......
configuration.addDirectory(mappingJarsLocation);
or
configuration.addJar(mappingJars);
but the Thread.currentThread().getContextClassLoader().getResource("mappings.jar") returns null
JBoss AS 4.2.3 it was working.
-
6. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
sfcoy Nov 23, 2011 5:44 AM (in response to nick.sree)Did you try "lib/mappings.jar"?
-
7. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
jaikiran Nov 23, 2011 5:54 AM (in response to nick.sree)By the way, where and when is that code being exceuted? The thread context classloader won't be null if it's being run as part of the usual EE request. But if you are running that code at some other point then the TCCL might not be set.
-
8. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 24, 2011 1:08 AM (in response to jaikiran)TCCL is there but TCCL#getResource("mappings.jar") is returning null.
-
9. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 24, 2011 1:37 AM (in response to sfcoy)I tried all possible way to pass mappings.jar location.
-
10. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
jaikiran Nov 24, 2011 1:49 AM (in response to nick.sree)Nick . wrote:
TCCL is there but TCCL#getResource("mappings.jar") is returning null.
See this then http://community.jboss.org/thread/174526?tstart=0
-
11. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 25, 2011 3:58 AM (in response to jaikiran)Its says to embbed mappings.jar inside another jar file. In our deployment plan its a little difficult task, Can you please suggest some straight way to get the path of deployment/xyz.ear/lib programatically.
-
12. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
sfcoy Nov 25, 2011 7:54 PM (in response to nick.sree)I suspect that there's no easy solution to this.
Consider biting the bullet and adding mapping elements to your hibernate.cfg.xml file. Hibernate will then locate your mappings as regular resources on the classpath. Even if you have a 100 mappings, you should be up and running in an hour or so.
-
13. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
nick.sree Nov 27, 2011 6:12 AM (in response to sfcoy)Hi Stephen...
Its pretty tuff task for us to include all the hbm inside cfg, sice our ERP product is having more than 500 hbm files and its located in various module jars. Right now we are doing some hack to get the mappings.jar location. But we are literally disappointed with that approach. If anybody knows a neat way to get the path upto /lib folder would be great.
-
14. Re: Thread.currentThread().getContextClassLoader().getResource() is not working in JBoss AS 7 ?
sfcoy Nov 27, 2011 10:22 PM (in response to nick.sree)1 of 1 people found this helpfulI agree that 500 mapping files is too much for manual intervention.
In the short term I would consider the following steps:
- Write a quick and dirty jar analyzer that will write a list of all the mappings in a provided list of mapping jar files to a file. You could copy the logic in org.hibernate.cfg.Configuration.addJar(File) for this purpose.
- Include this file in your build in a well known location so that you can read it as a classpath resource.
- Change your initialisation code to call org.hibernate.cfg.Configuration.addResource(String) for each mapping record in the generated file
This would be a portable solution that will work without needing to access the mapping files through the file system at runtime.