<div dir="ltr">Not sure to understand #2: are you creating a classloader that is loading classes from the user&#39;s Eclipse project ? Is it based on URL classloader ? I don&#39;t why it is not working ?</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 16, 2018 at 10:12 AM, Dmitrii Bocharov <span dir="ltr">&lt;<a href="mailto:dbocharo@redhat.com" target="_blank">dbocharo@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div>it&#39;s a long time i&#39;m trying to make jbosstools-hibernate work with Java.</div><div>The main problem is the class loader: <a href="https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L58" target="_blank">https://github.com/<wbr>jbosstools/jbosstools-<wbr>hibernate/blob/<wbr>b3826209cae7327a91615e0c088006<wbr>e54a4b5447/plugins/org.<wbr>hibernate.eclipse/src/org/<wbr>hibernate/eclipse/console/<wbr>common/HibernateExtension.<wbr>java#L58</a>.</div><div><br></div><div><b>sub-problem #1 (getResource) method </b>(solved)</div><div>If you google how to load resources in Java 9, then you find that now you should do <i>classloader.<wbr>getUnnamedModule().<wbr>getResourceAsStream()</i> instead of previous <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><i>classloader</i><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><i>.<wbr>getResourceAsStream(). </i>But we want, that our code could be built inside Java 7 Execution Environment (see MANIFEST.MF). So what i did for the <i><a href="https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L88" target="_blank">getResource</a></i> method. If we have null for <i>super.getResource(name)</i>, then i manually search for resources next to hibernate.cfg.xml using java.nio.file.Files.<wbr>walkFileTree. And it works! It needs to be polished a little bit, but anyway it solves the problem.</span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><b>sub-problem #2 (findClass)</b></span><span style="font-weight:400;color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> method (HELP NEEDED)</span></span></div><div>After the resource is found (and in hibernate usually it&#39;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 <i><a href="https://github.com/jbosstools/jbosstools-hibernate/blob/b3826209cae7327a91615e0c088006e54a4b5447/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/console/common/HibernateExtension.java#L63" target="_blank">classloader.findClass</a></i> doesn&#39;t find anything (ClassNotFoundException). I tried to <i>HibernatePlugin.getDefault(<wbr>).getBundle().loadClass(name)</i>, because i found that this loading classes stuff is fixed in core Eclipse and bundles must load classes without problems, but it doesn&#39;t work either.</div><div><br></div><div>So my main questions are:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>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&#39;d be glad if you share them :)</div><div>2) How to load user classes correctly now in Java 9 in Eclipse?</div><div>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 <i style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">classloader.<wbr>getUnnamedModule().<wbr>getResourceAsStream() </i><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">there? And switching between them using extension points mechanism. Is it possible? Does it worth it? If yes, then it&#39;ll require quite big work, in my opinion.</span></div><div><br></div></blockquote><br><div>Looking forward to any help.</div><div>Thanks in advance!</div><span class="HOEnZb"><font color="#888888"><div>Bocharov Dmitrii</div></font></span></div>
<br>______________________________<wbr>_________________<br>
jbosstools-dev mailing list<br>
<a href="mailto:jbosstools-dev@lists.jboss.org">jbosstools-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/jbosstools-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/jbosstools-<wbr>dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><p style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-weight:bold;margin:0px;padding:0px;font-size:14px;text-transform:uppercase"><span>JEFF</span> <span>MAURY</span></p><p style="font-family:overpass,sans-serif;margin:0px;font-size:10px;color:rgb(153,153,153)"><a href="https://www.redhat.com/" style="color:rgb(0,136,206);margin:0px;text-decoration:none" target="_blank">Red Hat <span><br><br></span></a></p><p style="font-family:overpass,sans-serif;margin:0px 0px 6px;font-size:10px;color:rgb(153,153,153)"><span style="margin:0px;padding:0px"><a href="mailto:jmaury@redhat.com" style="color:rgb(0,136,206);margin:0px;text-decoration:none" target="_blank">jmaury@redhat.com</a>   </span></p><table border="0" style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:medium"><tbody><tr><td width="100px"><a href="https://red.ht/sig" target="_blank"><img src="https://www.redhat.com/files/brand/email/sig-redhat.png" width="90" height="auto"></a></td><td style="font-size:10px"><div><a href="https://redhat.com/summit" style="text-decoration:none" target="_blank"><img width="70px" height="auto" src="https://www.redhat.com/files/brand/email/sig-summit.png" style="outline:0px"></a></div></td></tr></tbody></table><div style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:10px"><div style="color:rgb(153,153,153)"><a href="https://twitter.com/redhatjobs" title="twitter" style="background-image:url(&quot;https://www.redhat.com/files/brand/email/sm-twitter.png&quot;);height:20px;text-decoration:none;color:rgb(119,119,119);display:inline-block;line-height:20px;padding-left:16px;background-repeat:no-repeat;background-position:0px 50%" target="_blank">@redhatjobs</a>   <a href="https://www.facebook.com/redhatjobs/" title="facebook" style="background-image:url(&quot;https://www.redhat.com/files/brand/email/sm-facebook.png&quot;);height:20px;text-decoration:none;color:rgb(119,119,119);display:inline-block;line-height:20px;padding-left:16px;background-repeat:no-repeat;background-position:0px 50%" target="_blank">redhatjobs</a>   <a href="https://instagram.com/redhatjobs" title="instagram" style="background-image:url(&quot;https://www.redhat.com/files/brand/email/sm-instagram.png&quot;);height:20px;text-decoration:none;color:rgb(119,119,119);display:inline-block;line-height:20px;padding-left:16px;background-repeat:no-repeat;background-position:0px 50%" target="_blank">@redhatjobs</a>  </div></div></div></div>
</div>