johnthuss commented on issue #383: Cgen - Avoid class loader issues causing 
missing classes
URL: https://github.com/apache/cayenne/pull/383#issuecomment-491950976
 
 
   Thanks for looking into this! I realized that DbGeneratorTask already had a
   fix in it for this same issue, so I just followed that pattern and
   committed a fix to master.
   
   On Sat, May 11, 2019 at 9:58 AM Arseni Bulatski <[email protected]>
   wrote:
   
   > You can add implementation of ClassLoaderManager to cayenne-ant module.
   > For example
   >
   > public class AntClassLoaderManager implements ClassLoaderManager {
   >
   >     @Override
   >     public ClassLoader getClassLoader(String resourceName) {
   >         ClassLoader parentLoader = 
Thread.currentThread().getContextClassLoader();
   >
   >         if (parentLoader == null) {
   >             parentLoader = AntClassLoaderManager.class.getClassLoader();
   >         }
   >
   >         ClassLoader classLoader = parentLoader;
   >         return new ClassLoader() {
   >             @Override
   >             public Class<?> loadClass(String name) throws 
ClassNotFoundException {
   >                 try {
   >                     return classLoader.loadClass(name);
   >                 } catch (Exception ex) {
   >                     return 
AntClassLoaderManager.class.getClassLoader().loadClass(name);
   >                 }
   >             }
   >         };
   >     }
   > }
   >
   > And then add
   > binder ->
   > binder.bind(ClassLoaderManager.class).to(AntClassLoaderManager.class)
   > to cgen task.
   > I tested it in your project and in mine project too. It worked.
   > But there are some doubts about second classLoader.
   > Is it the same for all cases?
   >
   > —
   > You are receiving this because you authored the thread.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/cayenne/pull/383#issuecomment-491518058>, or 
mute
   > the thread
   > 
<https://github.com/notifications/unsubscribe-auth/AAC22RWGZI2AOJ32FX3M6P3PU3NKLANCNFSM4HLCZENA>
   > .
   >
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to