You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by rsantos <ru...@harvard.edu> on 2010/05/05 21:14:30 UTC
ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Hi,
I am enhancing my persistent classes at build time via ant. If I compile
the classes and then run the enhancer, it works fine. If I run the enhancer
again over classes that have already been enhanced, I get a
ClassNotFoundException on the first persistent class it tries. According to
the documentation, this should work. Does anyone have any ideas of what I am
doing wrong?
I am using OpenJPA 2.0.0.
The exception I get is:
[openjpac] java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException: bean.system.User
[openjpac] at serp.util.Strings.toClass(Strings.java:164)
[openjpac] at serp.util.Strings.toClass(Strings.java:108)
[openjpac] at serp.bytecode.BCClass.getType(BCClass.java:566)
[openjpac] at
org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:256)
[openjpac] at
org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4653)
[openjpac] at
org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
[openjpac] at
org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:171)
[openjpac] at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[openjpac] at org.apache.tools.ant.Task.perform(Task.java:364)
[openjpac] at org.apache.tools.ant.Target.execute(Target.java:341)
[openjpac] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[openjpac] at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[openjpac] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[openjpac] at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
[openjpac] at
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[openjpac] at
org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[openjpac] at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[openjpac] at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
BUILD FAILED
C:\Documents and Settings\rsantos\workspace_jpa\openjpa\build.xml:32:
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
bean.system.User
The ant target is:
<path id="project.classpath">
<fileset dir="webroot/WEB-INF/lib">
<!-- openjpa jar is here -->
<include name="**/*.jar"/>
</fileset>
</path>
<target name="enhance">
<taskdef name="openjpac" classpathref="project.classpath"
classname="org.apache.openjpa.ant.PCEnhancerTask"/>
<openjpac> <!-- LINE 32 of build.xml -->
<config propertiesFile="java/META-INF/persistence.xml"/>
<classpath>
<pathelement location="webroot/WEB-INF/classes" />
</classpath>
</openjpac>
</target>
Thanks,
Rute
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5010582.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Posted by Pinaki Poddar <pp...@apache.org>.
1. check where the enhanced classes generated after the first successful
enhancement. By default, enhancer overwrites the original *.class file. Make
sure that either is the case or there is only one version of
bean.system.User.class in the classpath.
2. Switch on the log, openjpa.Log=Tool=TRACE,Enhance=TRACE to get more
verbose logging.
3. Is it possible that the enhanced classes are in a jar file?
-----
Pinaki
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5011532.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
1. How does persistence.xml exactly refer to the orm.xml? Are these in the
same directory?
2. Can you replace <openjpac> with direct invocation of PCEnhancer and see
if there is any difference.
<java classname="..openjpa.enhance.PCEnhancer" fork="true">
<classpath refid="that.includes.web-inf.classes.and.openjpa.jar">
<arg value="-properties">
<arg value="META-INF/persistence.xml#MyUnit">
</java>
notice how #MyUnit is used to qualify the persistence.xml. Here MyUnit
is the name of the persistence unit.
-----
Pinaki
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5014448.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Posted by rsantos <ru...@harvard.edu>.
Hi Pinaki,
Thanks for the reply.
1. I am using the default so the classes are overwritten. I can tell that
because, after the enhancer runs successfully the first time, I can see that
the class files get larger. There aren't any other versions of that class in
the classpath. Here's my project structure:
/java
/bean/core/ (.java files and orm.xml files)
/bean/system/
/bean/workflow/
/driver
/META-INF/persistence.xml
/webroot
/WEB-INF
/classes (where the class files are generated and
META-INF/persistence.xml is copied when building)
/lib
mysql-connector-java-5.1.6-bin.jar
openjpa-all-2.0.0-beta3.jar
web.xml
2. The log didn't help me a lot. This is what I got:
$ ant enhance
Buildfile: build.xml
enhance:
[openjpac] 94 openjpa INFO [main] openjpa.Tool - No targets were given.
Ru
nning on all classes in your persistent classes list, or all metadata files
in c
lasspath directories if you have not listed your persistent classes. Use
-help
to display tool usage information.
[openjpac] 94 openjpa TRACE [main] openjpa.Tool - Enhancer running on
type "
bean.system.User".
[openjpac] java.lang.IllegalArgumentException:
java.lang.ClassNotFoundException
: bean.system.User
[openjpac] at serp.util.Strings.toClass(Strings.java:164)
[openjpac] at serp.util.Strings.toClass(Strings.java:108)
[openjpac] at serp.bytecode.BCClass.getType(BCClass.java:566)
[openjpac] at
org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:
256)
[openjpac] at
org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:465
3)
[openjpac] at
org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTas
k.java:89)
[openjpac] at
org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.
java:171)
[openjpac] at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
va:288)
[openjpac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
[openjpac] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[openjpac] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[openjpac] at java.lang.reflect.Method.invoke(Method.java:597)
[openjpac] at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchU
tils.java:105)
[openjpac] at org.apache.tools.ant.Task.perform(Task.java:348)
[openjpac] at org.apache.tools.ant.Target.execute(Target.java:357)
[openjpac] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[openjpac] at
org.apache.tools.ant.Project.executeSortedTargets(Project.jav
a:1329)
[openjpac] at
org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[openjpac] at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(De
faultExecutor.java:41)
[openjpac] at
org.apache.tools.ant.Project.executeTargets(Project.java:1181
)
[openjpac] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[openjpac] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[openjpac] at
org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[openjpac] at
org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
BUILD FAILED
c:\Documents and Settings\rsantos\workspace_jpa\openjpa\build.xml:32:
java.lang.
IllegalArgumentException: java.lang.ClassNotFoundException: bean.system.User
Total time: 0 seconds
Just a note: if I try to run the enhancer with no classes in
webroot/WEB-INF/classes, I get a different message: "Found no class to
enhance".
3. The only jars I have in the project are the openjpa and mysql connector
jars.
Is there anything wrong with my class/mapping? My bean.system.User class:
package bean.system;
import java.io.Serializable;
public class User {
private String userId;
private String name;
public User() {
}
protected User(String userId, String name) {
this.userId = userId;
this.name = name;
}
public static User createUser(String userId, String name) {
return new User(userId, name);
}
public static class UserId implements Serializable {
static {
// register persistent class in JVM
try {
Class.forName("bean.system.User");
} catch (Exception e) {
}
}
public String userId;
public UserId(String userId) {
this.userId = userId;
}
public UserId() {
this.userId = "";
}
public String toString() {
return userId;
}
public boolean equals(Object object) {
return object instanceof UserId
&& ((UserId) object).userId.equals(userId);
}
public int hashCode() {
return userId.hashCode();
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
The orm.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<package>
bean.system
</package>
<access>
FIELD
</access>
<entity class="bean.system.User">
<table name="users"/>
<id-class class="bean.system.User$UserId"/>
<attributes>
<id name="userId" />
<basic name="name"/>
</attributes>
</entity>
</entity-mappings>
Thanks in advance,
Rute
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5014297.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
> 2. Using the direct invocation of PCEnhancer worked fine!!!!!
Good.
> but I will try to make it work with the ant task. It's most likely a
> classpath problem on my side...
Or it may be PCEnhancerTask not recognizing Ant's classpath refid="..."
syntax well. PCEnhancerTask may even be older than refid="..." syntax.
-----
Pinaki
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5014758.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassNotFoundException in PCEnhancerTask when class has already
been enhanced
Posted by rsantos <ru...@harvard.edu>.
Hi Pinaki,
1. No, they aren't in the same directory. I have 3 orm.xml files, each in
a directory that has persistent classes. I refer to them in persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<persistence-unit name="openjpa" transaction-type="RESOURCE_LOCAL">
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>bean/core/orm.xml</mapping-file>
<mapping-file>bean/system/orm.xml</mapping-file>
<mapping-file>bean/workflow/orm.xml</mapping-file>
<properties>
<property name="openjpa.ConnectionUserName"
value="xxx"/>
<property name="openjpa.ConnectionPassword"
value="xxx"/>
<property name="openjpa.ConnectionDriverName"
value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionURL"
value="jdbc:mysql://de-dev-db2.de-dev.harvard.edu/rute_test"/>
<property name="openjpa.MetaDataFactory"
value="jpa"/>
<property name="openjpa.Log" value="Tool=TRACE,Enhance=TRACE"/>
<!-- This is already the default! -->
<property name="openjpa.TransactionMode" value="local" />
<!-- Will re-use Kodo's field JDOLOCKX -->
<property name="openjpa.jdbc.MappingDefaults"
value="VersionStrategy=version-number,VersionColumnName='JDOLOCKX'"/>
</properties>
</persistence-unit>
</persistence>
2. Using the direct invocation of PCEnhancer worked fine!!!!!
<target name="enhance">
<java classname="org.apache.openjpa.enhance.PCEnhancer" fork="true">
<classpath>
<pathelement location="webroot/WEB-INF/classes" />
<fileset dir="webroot/WEB-INF/lib">
<include name="openjpa-all-2.0.0.jar"/>
</fileset>
</classpath>
<arg value="-properties" />
<arg value="java/META-INF/persistence.xml#openjpa" />
</java>
</target>
For now, I can use the direct invocation, but I will try to make it work
with the ant task. It's most likely a classpath problem on my side...
Thanks a lot for your help!
Rute
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassNotFoundException-in-PCEnhancerTask-when-class-has-already-been-enhanced-tp5010582p5014661.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.