You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2013/10/03 19:04:21 UTC

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Hi

Is it on trunk?

Are you sure you didnt put openjpa in your app?

If not I recall we had an issue with our javaagent, maybe give a try
removing it from catalina.sh
Le 3 oct. 2013 18:59, "wlad" <vv...@yahoo.com> a écrit :

> Hi,
> I am using Eclipse IDE, TomEE server and MySQL database.
> I am working on simple JEE example that should demonstrate connecting to
> database using EntityManagerFactory, EntityManager, EntityTransaction -
> persist entities to database, find them by ID, update, remove.
> All these operations are in "public static void main" method of client
> class.
>
> I have created database connection in Data Source Explorer, and ant tasks
> for creating database (sql code for creating db). Database creation works
> fine, but when I try to run client class I am getting next exception:
>
> /Buildfile: /home/vladimir/workspace/MBS-Vezbe/V7/build.xml
> runClient01:
>      [java] Entity Manager Factory created
>      [java] Exception in thread "main" java.lang.LinkageError: loader
> (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class
> definition for name:
> "org/apache/openjpa/jdbc/identifier/DBIdentifier$DBIdentifierType"
>      [java]     at java.lang.ClassLoader.defineClass1(Native Method)
>      [java]     at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
>      [java]     at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
>      [java]     at
> java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
>      [java]     at
> java.net.URLClassLoader.access$100(URLClassLoader.java:71)
>      [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
>      [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
>      [java]     at java.security.AccessController.doPrivileged(Native
> Method)
>      [java]     at
> java.net.URLClassLoader.findClass(URLClassLoader.java:354)
>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>      [java]     at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>      [java]     at
>
> org.apache.openjpa.jdbc.sql.DBDictionary.configureNamingRules(DBDictionary.java:506)
>      [java]     at
>
> org.apache.openjpa.jdbc.sql.DBDictionary.setConfiguration(DBDictionary.java:4633)
>      [java]     at
>
> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:486)
>      [java]     at
>
> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
>      [java]     at
>
> org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:199)
>      [java]     at
>
> org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:66)
>      [java]     at
>
> org.apache.openjpa.jdbc.sql.DBDictionaryFactory.calculateDBDictionary(DBDictionaryFactory.java:81)
>      [java]     at
>
> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:584)
>      [java]     at
>
> org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)
>      [java]     at
>
> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)
>      [java]     at
>
> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
>      [java]     at
> org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
>      [java]     at
>
> org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
>      [java]     at
> org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
>      [java]     at
>
> org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:968)
>      [java]     at
>
> org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:959)
>      [java]     at
>
> org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638)
>      [java]     at
>
> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
>      [java]     at
>
> org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
>      [java]     at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
>      [java]     at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
>      [java]     at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
>      [java]     at
>
> rs.ac.uns.ftn.informatika.mbs2.vezbe07.primer01.client.TestClient.main(TestClient.java:23)
>      [java] Java Result: 1
> BUILD SUCCESSFUL
> Total time: 2 seconds/
>
> This exception happens when executing source code line: "EntityManager
> manager = factory.createEntityManager();"
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
"Classloader" exception i was getting, could be due some incompatibility
between openjpa and java 1.7 version. I was getting this same exception with
OpenJDK 1.7, and also with Oracle's java 1.7 version. Removed 1.7, and
installed OpenJDK 1.6 and now it works.




--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665609.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
Hi,
You are totally correct (i myself didn't realize that at first). Actually
ant deploy task is not important. It is just here beacause build.xml was
build the way its content was copied from some other project that was
deploying its jars to tomee, so some ant tasks remained there (even they do
nothing).

In this example, actually tomee is not beeing used, only JPA API. So, client
can be run as Java Application.
The create-database ant task works fine (execute sql script), it does create
tables in previously created mysql database (db name: v7). And then
runClient task (TestClient class) should connect to database, persist,
update, remove entities from database, and list them.

It is my fault that i didn't realize that tomee is actually not used when
running client! I apologize on that, i'm still learning from these examples.



--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665422.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

I don't get at all what you deploy.

Your project builds a jar so you need to deploy it in <tomee>/apps once the
line <Deployments dir="apps" /> activated (eclipse doesn't know how to do
so)

then your client is a main but i don't get how you want to call it from
tomee

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/10/4 wlad <vv...@yahoo.com>

> Romain Manni-Bucau wrote
> > Hmm
> >
> > it is works in normal mode you should contact eclipse guys IMO
>
> I have downloaded Eclipse Juno version, set up TomEE, and again getting
> same
> exception. Same situation.
> Anyway, thanks for help. I will keep digging, and if i solve this, i will
> post what i did.
> Thank again for your time.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665420.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
Romain Manni-Bucau wrote
> Hmm
> 
> it is works in normal mode you should contact eclipse guys IMO

I have downloaded Eclipse Juno version, set up TomEE, and again getting same
exception. Same situation. 
Anyway, thanks for help. I will keep digging, and if i solve this, i will
post what i did.
Thank again for your time.



--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665420.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm

it is works in normal mode you should contact eclipse guys IMO

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/10/4 wlad <vv...@yahoo.com>

> wlad wrote
> > "Turns out adding jvm option -XX:+AlwaysLockClassLoader appears to
> resolve
> > issue. "
> >
> > Now, how could i try that? How can i add -XX:+AlwaysLockClassLoader
> option
> > to jvm?
>
> [to answer my own question]
> I tried adding -XX:+AlwaysLockClassLoader option to jvm (Run
> Configuration->Arguments tab->VM arguments, added
> -XX:+AlwaysLockClassLoader) - didn't help.
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665409.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
wlad wrote
> "Turns out adding jvm option -XX:+AlwaysLockClassLoader appears to resolve
> issue. "
> 
> Now, how could i try that? How can i add -XX:+AlwaysLockClassLoader option
> to jvm?

[to answer my own question]
I tried adding -XX:+AlwaysLockClassLoader option to jvm (Run
Configuration->Arguments tab->VM arguments, added
-XX:+AlwaysLockClassLoader) - didn't help.




--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665409.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
I'm running out of ideas, and appreciate any advice and comment. 
I am fresh TomEE user, and wasn't expecting this much troubles with just
trying to run some simple (valid) examples. May be, that I am missing some
simple server setting, that could be the option! But, from the errors i'm
getting, and because similar problem happened to experienced developers
before, it looks like it is TomEE bug.(ok that should cover me)

To summarize:

- "java -version" gives:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)

- Eclipse Kepler IDE

- apache-tomee-plus-1.6.0-SNAPSHOT
   - set to Use Tomcat installation(takes control of Tomcat installation)
   - i have also noticed that tomee app: http://localhost:8080/tomee/ is not
working with 1.6.0-SNAPSHOT (Connection exception - The application is
waiting for the server), and it worked with tomee-plus-1.5.2. (in
tomcat-users.xml, "tomee" user parameters are activated, uncommented). I
find it useful because I could see JNDI names of deployed beans from there.

- MySQL server/client installed

- examples I am trying to run have all jar libraries they need in the lib
folders inside its project folder, and included to build path from there
(idea is that project should be independent from server jar libraries)
- simple example that just deploys session bean to Tomee, finds it by JNDI
name and invokes its method works fine
- examples that should use JPA (OpenJPA) are causing this "Classloader"
error when on this line: EntityManager manager =
factory.createEntityManager();

- I tried adding -XX:+AlwaysLockClassLoader option to jvm (Run
Configuration->Arguments tab->VM arguments, added
-XX:+AlwaysLockClassLoader) - didn't help.

- i tried commenting next lines in catalina.sh:
/#if [ -r "$CATALINA_HOME"/lib/openejb-javaagent.jar ]; then 
#  JAVA_OPTS=""-javaagent:$CATALINA_HOME/lib/openejb-javaagent.jar"
$JAVA_OPTS" 
#fi/
didn't help.

- then as Romain Manni-Bucau suggested, to set CATALINA_OPTS env variable, i
did next:
   - as stated in catalina.sh " to keep your customizations separate put
them into a script setenv.sh in CATALINA_BASE/bin."
   - i have created apache-tomee-plus-1.6.0-SNAPSHOT/bin/setenv.sh with one
line in it:
       /CATALINA_OPTS=""-javaagent:$CATALINA_HOME/lib/openejb-javaagent.jar"
$CATALINA_OPTS" /
  - still getting same exception.
Again, if you want to see(and try) example i'm trying to run, you can
download it  from here <http://ge.tt/3bpbsjt/v/0>  . Just run "create
database v7" in mysql terminal, set properties in build.properties file, and
try to run ant tasks.
Thanks.



--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665416.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by Romain Manni-Bucau <rm...@gmail.com>.
You can put it in CATALINA_OPTS environment variable.

But if you handle to reproduce it in a sample please share it.

This issue should be fixed on trunk, if not we need to address it.
Le 4 oct. 2013 00:01, "wlad" <vv...@yahoo.com> a écrit :

> Romain Manni-Bucau wrote
> > Did tou try 1.6.0-snapshot (trunk) version?
>
> Hi,
> I have downloaded and set up "apache-tomee-plus-1.6.0-SNAPSHOT" version
> (following  your blog
> <http://rmannibucau.wordpress.com/2012/05/23/getting-tomee-snapshot/>  ),
> but am still getting same error. Other example i have, that does not use
> database (just deploying session bean to Tomee, find it by JNDI name and
> calling a method) works fine.
>
> I have found that same "Classloader" issues was reported on  one of the
> topics on OpenJPA Users mailing list
> <
> http://openjpa.208410.n2.nabble.com/JDK-1-7-seems-to-be-causing-an-issue-with-latest-snapshot-td7581417.html
> >
> .
>
> And from that topic, it seems like there is no unique solution, but one
> post
> says:
> "Turns out adding jvm option -XX:+AlwaysLockClassLoader appears to resolve
> issue. "
>
> Now, how could i try that? How can i add -XX:+AlwaysLockClassLoader option
> to jvm?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665408.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
Romain Manni-Bucau wrote
> Did tou try 1.6.0-snapshot (trunk) version?

Hi,
I have downloaded and set up "apache-tomee-plus-1.6.0-SNAPSHOT" version
(following  your blog
<http://rmannibucau.wordpress.com/2012/05/23/getting-tomee-snapshot/>  ),
but am still getting same error. Other example i have, that does not use
database (just deploying session bean to Tomee, find it by JNDI name and
calling a method) works fine.

I have found that same "Classloader" issues was reported on  one of the
topics on OpenJPA Users mailing list
<http://openjpa.208410.n2.nabble.com/JDK-1-7-seems-to-be-causing-an-issue-with-latest-snapshot-td7581417.html> 
.

And from that topic, it seems like there is no unique solution, but one post
says:
"Turns out adding jvm option -XX:+AlwaysLockClassLoader appears to resolve
issue. "

Now, how could i try that? How can i add -XX:+AlwaysLockClassLoader option
to jvm?



--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665408.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Did tou try 1.6.0-snapshot (trunk) version?
Le 3 oct. 2013 20:27, "wlad" <vv...@yahoo.com> a écrit :

> Romain Manni-Bucau wrote
> > Is it on trunk?
>
> Hi Romain,
> I'm pretty new in these things, and not quite sure I understand some
> details. Maybe its my limited english, but what do you mean by "to be on a
> trunk"?
>
>
> Romain Manni-Bucau wrote
> > Are you sure you didnt put openjpa in your app?
>
> I do have "openjpa-asm-shaded-2.2.0.jar" included in app (added to build
> path). If i remove it from build path, i am getting same error.
>
>
> Romain Manni-Bucau wrote
> > If not I recall we had an issue with our javaagent, maybe give a try
> > removing it from catalina.sh
>
> This is not the same example, this is new, different project. In this one i
> am trying to communicate with database, but getting this exception.
> Could this error be due to some wrong datasource setting?
> What i have done is, that first I have just created empty database from
> terminal with command: "create database v7"
> Then, in eclipse, I have created DB connection from Data Source Explorer
> giving next parameters:
> Database: V7DB
> URL: jdbc:mysql://localhost:3306/v7
> Username: root
> Password: 123
> and when I Test Connection it works (Ping Succeeded).
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665404.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
Romain Manni-Bucau wrote
> Is it on trunk?

Hi Romain,
I'm pretty new in these things, and not quite sure I understand some
details. Maybe its my limited english, but what do you mean by "to be on a
trunk"?


Romain Manni-Bucau wrote
> Are you sure you didnt put openjpa in your app?

I do have "openjpa-asm-shaded-2.2.0.jar" included in app (added to build
path). If i remove it from build path, i am getting same error.


Romain Manni-Bucau wrote
> If not I recall we had an issue with our javaagent, maybe give a try
> removing it from catalina.sh

This is not the same example, this is new, different project. In this one i
am trying to communicate with database, but getting this exception. 
Could this error be due to some wrong datasource setting?
What i have done is, that first I have just created empty database from
terminal with command: "create database v7"
Then, in eclipse, I have created DB connection from Data Source Explorer
giving next parameters:
Database: V7DB
URL: jdbc:mysql://localhost:3306/v7
Username: root
Password: 123
and when I Test Connection it works (Ping Succeeded).





--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665404.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Getting exception: "java.lang.LinkageError:" ... attempted duplicate class definition for name...

Posted by wlad <vv...@yahoo.com>.
wlad wrote
> When you say remove javaagent from catalina.sh, do you mean removing(or
> just putting #, commenting) next lines from catalina.sh by that?
/
> # Add OpenEJB javaagent
> if [ -r "$CATALINA_HOME"/lib/openejb-javaagent.jar ]; then
>   JAVA_OPTS=""-javaagent:$CATALINA_HOME/lib/openejb-javaagent.jar"
> $JAVA_OPTS"
> fi
/
I tried with those lines commented, but still getting same error.



--
View this message in context: http://openejb.979440.n4.nabble.com/Getting-exception-java-lang-LinkageError-attempted-duplicate-class-definition-for-name-tp4665401p4665412.html
Sent from the OpenEJB User mailing list archive at Nabble.com.