enhancement issue

#1

Hi, still struggling with the enhancement issue.

So, this works fine in development:

static void main ( String[] args ) {
    com.objectdb.Enhancer.enhance ( "app.model.*" )
    ....
  }
}

But in deployment, when the jar files is made with ShadowJar, this error occurs at runtime:

[ObjectDB 2.7.1_02] Package app.model is not found by the enhancer (error 108)
com.objectdb.o.UserException: Package app.model is not found by the enhancer
        at com.objectdb.o.MSG.d(MSG.java:62)
        at com.objectdb.o.JEL.z(JEL.java:415)
        at com.objectdb.o.JEN.m(JEN.java:99)
        at com.objectdb.Enhancer.enhance(Enhancer.java:69)
        at com.objectdb.Enhancer.enhance(Enhancer.java:90)

So, the enhancer can't find the classes when they are in a jar file??

 

#2

To enhance a jar file you need to:

  • Have the JAR file in the classpath that is available to ObjectDB. Sometimes setting the context class loader before accessing ObjectDB (or calling enhance) could help:
Thread.currentThread().setContextClassLoader(MyEntity.class.getClassLoader());

where MyEntity is one of your classes.

  • ObjectDB doesn't support writing the enhanced classes back to a JAR file, so you have to specify a destination path for writing the enhanced classes as class files (using -d), and of course you have to make sure that the path is included in the application classpath before the jar file.

Alternatively you may find build time enhancement or enhancement by an agent (specifying it explicitly with -javaagent explicitly) more suitable.

ObjectDB Support

Reply