tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: Multiple persistence.xml in different jars
Date Tue, 14 Oct 2014 14:43:25 GMT
asm4? you are not on tomee 1.7?


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-10-14 16:40 GMT+02:00 Mansour Al Akeel <mansour.alakeel@gmail.com>:
> Thank you Romain.
> The target/classes was in the class path, but the size of the url array was 0.
>
> This was helpful. I am getting another error, that I was not able to understand.
>
> SEVERE: FATAL ERROR: Unknown error in Assembler.  Please send the
> following stack trace and this message to users@openejb.apache.org :
>  java.lang.IllegalArgumentException
>         at org.apache.xbean.asm4.ClassReader.<init>(Unknown Source)
>         at org.apache.xbean.asm4.ClassReader.<init>(Unknown Source)
>         at org.apache.xbean.asm4.ClassReader.<init>(Unknown Source)
>         at org.apache.openejb.util.AnnotationFinder.readClassDef(AnnotationFinder.java:297)
>         at org.apache.openejb.util.AnnotationFinder.find(AnnotationFinder.java:163)
>         at org.apache.openejb.config.DeploymentLoader.checkAnnotations(DeploymentLoader.java:1871)
>         at org.apache.openejb.config.DeploymentLoader.discoverModuleType(DeploymentLoader.java:1782)
>         at org.apache.openejb.config.DeploymentsResolver.processUrls(DeploymentsResolver.java:388)
>         at org.apache.openejb.config.DeploymentsResolver.loadFromClasspath(DeploymentsResolver.java:301)
>         at org.apache.openejb.config.ConfigurationFactory.getModulesFromClassPath(ConfigurationFactory.java:647)
>         at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:524)
>         at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:575)
>         at org.apache.openejb.assembler.classic.Assembler.getOpenEjbConfiguration(Assembler.java:429)
>         at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:408)
>         at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:148)
>         at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:65)
>         at org.apache.openejb.OpenEJB.init(OpenEJB.java:296)
>         at org.apache.openejb.OpenEJB.init(OpenEJB.java:276)
>
>
> I will continue digging.
>
> Thank you a lot.
>
>
> On Tue, Oct 14, 2014 at 2:20 AM, Romain Manni-Bucau
> <rmannibucau@gmail.com> wrote:
>> Hi
>>
>> we have a mojo like it
>> http://svn.apache.org/repos/asf/tomee/tomee/trunk/maven/openejb-embedded-maven-plugin/
>>
>> I think you miss target/classes in your loader
>>
>>
>> Romain Manni-Bucau
>> @rmannibucau
>> http://www.tomitribe.com
>> http://rmannibucau.wordpress.com
>> https://github.com/rmannibucau
>>
>>
>> 2014-10-14 6:37 GMT+02:00 Mansour Al Akeel <mansour.alakeel@gmail.com>:
>>> Romain,
>>> It was my fault. I was loading the persistence context using openjpa.
>>> However, switched to OpenEJB to allow scanning for the persistence.xml
>>> in other jars. The problem is the current jar has some EJBs. I am
>>> loading them from maven mojo. In a way, it's similar to unit testing.
>>>
>>>   protected void setupClassPath() throws MalformedURLException,
>>> DependencyResolutionRequiredException
>>>     {
>>>
>>>     synchronized (this)
>>>     {
>>>         if (classLoader != null)
>>>         return;
>>>     }
>>>     synchronized (this)
>>>     {
>>>         List<URL> urls = new ArrayList<URL>();
>>>
>>>         List<String> paths = new LinkedList<String>();
>>>
>>>         List<String> compilePath = mavenProject.getCompileClasspathElements();
>>>
>>>         List<String> testPath = mavenProject.getTestClasspathElements();
>>>
>>>         List<String> runtimePath = mavenProject.getRuntimeClasspathElements();
>>>
>>>         List<String> systemPath = mavenProject.getSystemClasspathElements();
>>>
>>>         List<Dependency> dependencies = mavenProject.getCompileDependencies();
>>>
>>>         this.merge(paths, compilePath);
>>>         this.merge(paths, testPath);
>>>         this.merge(paths, runtimePath);
>>>         this.merge(paths, systemPath);
>>>
>>>         getLog().info("Scanning ... ");
>>>
>>>         for (Object object : paths)
>>>         {
>>>         String path = (String) object;
>>>
>>>         getLog().info("Adding " + path + " to classpath");
>>>
>>>         urls.add(new File(path).toURL());
>>>         }
>>>
>>>         ClassLoader parent = Thread.currentThread().getContextClassLoader();
>>>
>>>         parent = this.getClass().getClassLoader();
>>>
>>>         ClassLoader contextClassLoader =
>>> URLClassLoader.newInstance(urls.toArray(new URL[0]), parent);
>>>
>>>         Thread.currentThread().setContextClassLoader(contextClassLoader);
>>>
>>>         return;
>>>     }
>>>     }
>>>
>>> .....
>>>
>>> properties.put(Context.INITIAL_CONTEXT_FACTORY,
>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>
>>>     // properties.put(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
>>>     properties.put("openejb.validation.output.level", "VERBOSE");
>>>
>>>     properties.put("jdbc/dataSource", "new://Resource?type=DataSource");
>>>     properties.put("jdbc/dataSource.JdbcDriver", this.driver);
>>>     properties.put("jdbc/dataSource.JdbcUrl", this.url);
>>>     properties.put("jdbc/dataSource.UserName", this.username);
>>>     properties.put("jdbc/dataSource.Password", this.password);
>>>
>>>     properties.setProperty("javax.persistence.transactionType",
>>> "RESOURCE_LOCAL");
>>>
>>>     Context ctx;
>>>     try
>>>     {
>>>
>>>         ctx = new InitialContext(properties);
>>>
>>>
>>> The problem I am facing now, is that not all the dependencies are
>>> available for OpenEJB:
>>>
>>> Oct 13, 2014 10:15:36 PM org.apache.openejb.OpenEJB$Instance <init>
>>> SEVERE: OpenEJB has encountered a fatal error and cannot be started:
>>> The Assembler encountered an unexpected error while attempting to
>>> build the container system.
>>> java.lang.NoClassDefFoundError:
>>> org/perfectjpattern/jee/integration/dao/AbstractJpaManagedBaseDao
>>>         at java.lang.ClassLoader.defineClass1(Native Method)
>>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
>>>         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
>>>         at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
>>>         at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
>>>         at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
>>>         at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
>>>         at java.security.AccessController.doPrivileged(Native Method)
>>>         at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
>>>         at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
>>>         at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
>>>         at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:180)
>>>         at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:74)
>>>         at org.apache.xbean.finder.archive.JarArchive.loadClass(JarArchive.java:84)
>>>         at org.apache.xbean.finder.archive.CompositeArchive.loadClass(CompositeArchive.java:58)
>>>         at org.apache.openejb.config.FinderFactory$DebugArchive.loadClass(FinderFactory.java:139)
>>>         at org.apache.xbean.finder.AnnotationFinder$ClassInfo.get(AnnotationFinder.java:1425)
>>>         at org.apache.xbean.finder.AnnotationFinder.findMetaAnnotatedClasses(AnnotationFinder.java:540)
>>>         at org.apache.xbean.finder.AnnotationFinder.findMetaAnnotatedClasses(AnnotationFinder.java:489)
>>>         at org.apache.openejb.config.FinderFactory$ModuleLimitedFinder.findMetaAnnotatedClasses(FinderFactory.java:291)
>>>         at org.apache.openejb.config.AnnotationDeployer$DiscoverAnnotatedBeans.deploy(AnnotationDeployer.java:1391)
>>>         at org.apache.openejb.config.AnnotationDeployer$DiscoverAnnotatedBeans.deploy(AnnotationDeployer.java:436)
>>>         at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:351)
>>>         at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:396)
>>>         at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:938)
>>>         at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:799)
>>>         at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:531)
>>>         at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:575)
>>>         at org.apache.openejb.assembler.classic.Assembler.getOpenEjbConfiguration(Assembler.java:429)
>>>         at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:408)
>>>         at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:148)
>>>         at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:65)
>>>         at org.apache.openejb.OpenEJB.init(OpenEJB.java:296)
>>>         at org.apache.openejb.OpenEJB.init(OpenEJB.java:276)
>>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>         at java.lang.reflect.Method.invoke(Method.java:606)
>>>         at org.apache.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:36)
>>>         at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:96)
>>>         at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:60)
>>>         at org.apache.openejb.core.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:44)
>>>
>>>
>>> I am not sure if adding dependencies to OpenEJB class works using
>>>
>>> Thread.currentThread().setContextClassLoader(contextClassLoader);
>>>
>>> Thank you.
>>>
>>>
>>> On Mon, Oct 13, 2014 at 7:10 AM, Romain Manni-Bucau
>>> <rmannibucau@gmail.com> wrote:
>>>> not for war and classpath apps (only for ears)
>>>>
>>>>
>>>> Romain Manni-Bucau
>>>> @rmannibucau
>>>> http://www.tomitribe.com
>>>> http://rmannibucau.wordpress.com
>>>> https://github.com/rmannibucau
>>>>
>>>>
>>>> 2014-10-13 13:07 GMT+02:00 Andy Gumbrecht <agumbrecht@tomitribe.com>:
>>>>> Could this be related the '*openejb.finder.module-scoped=true*' property?
>>>>>
>>>>> Andy.
>>>>>
>>>>>
>>>>> On 13/10/2014 08:39, Romain Manni-Bucau wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> it should do out of the box,can you share more details/code?
>>>>>>
>>>>>>
>>>>>> Romain Manni-Bucau
>>>>>> @rmannibucau
>>>>>> http://www.tomitribe.com
>>>>>> http://rmannibucau.wordpress.com
>>>>>> https://github.com/rmannibucau
>>>>>>
>>>>>>
>>>>>> 2014-10-13 7:40 GMT+02:00 Mansour Al Akeel <mansour.alakeel@gmail.com>:
>>>>>>>
>>>>>>> I am writing unit tests. The unit test include multiple jars,
each of
>>>>>>> them has JPA entities and persistence.xml file. Each file has
it's own
>>>>>>> Persistence Context.
>>>>>>>
>>>>>>>
>>>>>>> The JPA entities in jar B references some entities in jar file
A. I
>>>>>>> need to load both persistence.xml.
>>>>>>>
>>>>>>> Is there a way to instruct openejb container to scan for other
>>>>>>> persistence.xml in different jars ??
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>   Andy Gumbrecht
>>>>>   https://twitter.com/AndyGeeDe
>>>>>   http://www.tomitribe.com
>>>>>

Mime
View raw message