Question

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...

Was it helpful?

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.

OTHER TIPS

Consider using an Enterprise Application archetype for this.

Your DAL and BL would be contained in the EJB project, and the PL would be in the web project.

This specific case is exactly what this archetype is for, and will ensure that you're including the necessary libraries in each module, not just the compiled classes stripped of their dependancies.

As an aside, when using JPA, if your DAL/BL is encapsulated in EJB classes, you also get Container Managed Transactions, so it's a good idea to segregate classes as you have anyway, because you can take better advantage of JEE's extensive built-in plumbing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top