502 words

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

#1
2014-06-15 12:19

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?

 

ThreaT
ThreaT's picture
Joined on 2014-02-19
User Post #21
#2
2014-06-15 12:41

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,960
#3
2014-06-15 12:50

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?

ThreaT
ThreaT's picture
Joined on 2014-02-19
User Post #22
#4
2014-06-16 11:31

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,961

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel