[jbosstools-dev] [HELP NEEDED] Java 9 and jbosstools-hibernate

Dmitrii Bocharov dbocharo at redhat.com
Fri Mar 16 05:12:46 EDT 2018


Hi
it's a long time i'm trying to make jbosstools-hibernate work with Java.
The main problem is the class loader:
https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L58
.

*sub-problem #1 (getResource) method *(solved)
If you google how to load resources in Java 9, then you find that now you
should do *classloader.getUnnamedModule().getResourceAsStream()* instead of
previous *classloader**.getResourceAsStream(). *But we want, that our code
could be built inside Java 7 Execution Environment (see MANIFEST.MF). So
what i did for the *getResource
<https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L88>*
method. If we have null for *super.getResource(name)*, then i manually
search for resources next to hibernate.cfg.xml
using java.nio.file.Files.walkFileTree. And it works! It needs to be
polished a little bit, but anyway it solves the problem.

*sub-problem #2 (findClass)* method (HELP NEEDED)
After the resource is found (and in hibernate usually it's a mapping xml
file) using the solution above, we try to associate it with the class and
load it with the classloader. However, the current *classloader.findClass
<https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L63>*
doesn't find anything (ClassNotFoundException). I tried to
*HibernatePlugin.getDefault().getBundle().loadClass(name)*, because i found
that this loading classes stuff is fixed in core Eclipse and bundles must
load classes without problems, but it doesn't work either.

So my main questions are:

1) This code is rather old, and i suppose that it must be refactored in
general. If you have any thoughts of how to do it better, i'd be glad if
you share them :)
2) How to load user classes correctly now in Java 9 in Eclipse?
3) Maybe the better way is to create a plugin/feature with a minimal
Execution Environment set to Java 9, which will be activated only when java
9 is used and implement such things like
*classloader.getUnnamedModule().getResourceAsStream()
*there? And switching between them using extension points mechanism. Is it
possible? Does it worth it? If yes, then it'll require quite big work, in
my opinion.


Looking forward to any help.
Thanks in advance!
Bocharov Dmitrii
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jbosstools-dev/attachments/20180316/f1035b3d/attachment.html 


More information about the jbosstools-dev mailing list