Not sure to understand #2: are you creating a classloader that is loading classes from the user's Eclipse project ? Is it based on URL classloader ? I don't why it is not working ?

On Fri, Mar 16, 2018 at 10:12 AM, Dmitrii Bocharov <dbocharo@redhat.com> wrote:
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 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 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

_______________________________________________
jbosstools-dev mailing list
jbosstools-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jbosstools-dev



--

JEFF MAURY

Red Hat 

jmaury@redhat.com   

@redhatjobs   redhatjobs   @redhatjobs