ObjectDB ObjectDB

UserException: Package com.example.model is not found by the enhancer

#1

My program works fine when I run it from Netbeans but as soon as I clean and build and move the dist directory out of the project to a remote location and run it using java -jar example.jar then I get the exception:

com.objectdb.o.UserException: Package com.example.model is not found by the enhancer

It occurs on this line:

com.objectdb.Enhancer.enhance("com.example.model" + ".*");

during contextInitialization.

In my setup I'm using JDK 8, Object DB and Embedded Tomcat 8.0.3 so after clean and build my dist directory contains:
1. lib directory with all the jars

2. example.jar

3. README.txt

However, in my source code's lib directory I have:
\lib\objectdb-2.5.4_05\database\example.odb

Which is obviously not present when cleaning and building with Netbeans and moving the dist directory to a remote location.

What are the possible solutions around this problem as I'm not sure how the enhance() method looks up the model path since it will be inside the example.jar after building?

 

edit
delete
#2

It may be a class loader conflict, i.e. the Enhancer and your classes are loaded by different class loaders and the Enhancer do not have access to the classes.

Enhancing by invoking the Enhancer from the application (as demonstrated in your post) is not recommended. Alternative enhancement methods are listed in the manual. Build time enhancement is preferred, since it enables deployment of the web application with already enhanced classes, so there is no need to run the enhancer outside the development and build environments.

ObjectDB Support
edit
delete
#3

Build time enhancement is tricky since the path will change depending on which environment the jar is run on. Load time enhancement isn't really desired since it adds an additional command needing to be run before executing the jar. The most user-friendly, environment-friendly option seems to be via the enhancement API. Is there a way that I can get it to work within the code?

I've also tried commenting out the line:

//com.objectdb.Enhancer.enhance("com.example.model" + ".*");

and adding the following to the Netbeans IDE, Project, Run, VM Options:

java -javaagent:C:\work\programs\Object DB\objectdb-2.5.5_14\bin\objectdb.jar example

However, when I try to run the project from within Netbeans I now get this error:

Error: Could not find or load main class java
Java Result: 1


Also where does the .odb file get stored after building the jar and running it?

Also, it would be cool if Netbeans gave a warning when code referenced entity object member variables rather than getters and setters. I think if you use the @Warning annotation this can be achieved?

edit
delete
#4

Enhancement using an invocation of Enhancer.enhance is not recommended. If used, you must make sure that enhancement is performed before the enhanced classes are loaded, which could be tricky. Anyway, it should work if done before loading the classes for enhancement and when these classes are available in the classpath. This method is used in this tutorial.

The error message that you got when trying to invoke the javaagent enhancement indicates that the java keyword is unexpected. In the VM options you should only specify VM options, i.e. start with -javaagent ...

Please use separate form threads for other questions that are not in the the topic of this thread (which is enhancement).

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.