Search code examples
javajpanetbeansnoclassdeffounderrorpresentation-layer

Problems communicating Business Layer (JPA) with Presentation Layer (Netbeans 7.x)


I would like to develop a "database based" java desktop application in the following way:

  • Develop the Data Access Layer (DAL) using JPA (POJOs generated by Netbeans 7.4)
  • Develop the Business Layer (BL) (my own classes, controllers, etc.)
  • Develop the Presentation Layer (PL): Graphical User Interfaces (Panels, Frames, Dialogs)
  • Making the (PL) communicate with the (BL)

I developed the (DAL + BL) in a single Netbeans project (ProjectDBL.jar).

I developed the PL in a separate Netbeans project (ProjectGUI)

I am importing ProjectDBL.jar into ProjectGUI as a compiled library.

I didn't add the EclipseLink libraries to ProjectGUI since they were added in the ProjectDBL.jar.

I didn't add the database driver library to ProjectGUI for the same reasons.

I would like to fully separate between my DAL+BL and my PL. Further database modification (MySQL->SQLServer for example) should not impact all what was done in the PL.

The problem i am facing is a kind of exception raising when i want to invoke any method in the ProjectDBL.jar:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityNotFoundException

It seems as if the Persistence Unit must not be instantiated by an external jar...


Solution

  • A compiled library doesn't include all the libraries it uses. Otherwize, every jar file would be 50MBs large, and you would end up with commonly used libraries being present several times in your classpath.

    You neet to add every library you use, directly or indirectly, to the classpath.