0

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

mathematix
  • 366
  • 3
  • 10

2 Answers2

0

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Are there any best practice to be followed? I need to fully separate the development of the different components of my application. So adding the MySQL Driver library to my DAL project and to my GUI project does not seem to be an efficient way... – mathematix Apr 06 '14 at 13:36
  • Regarding libraries management in multiple sub-projects developed separately. – mathematix Apr 06 '14 at 13:40
  • Yes, there are best practices. Use a dependency management build tool like Gradle. – JB Nizet Apr 06 '14 at 13:42
0

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.

SplinterReality
  • 3,400
  • 1
  • 23
  • 45
  • If my DAL/BL project depends on some specific libraries (for example: EclipseLink, Database driver, etc...), i do not understand why i should import all these things to my Presentation Layer project !!! – mathematix Apr 06 '14 at 14:03
  • That's why you should use the EA archetype. Essentially what you get are 3 products: The EJB project, the Web Project, and a combined Enterprise project for convenience of deployment. (Plus one more project which controls the dependency relations of those 3) If you wish to deploy them separately, you can, provided your PL project can find the EJB project's remote interfaces. That gives you quite complete decoupling, and virtually no library contamination. – SplinterReality Apr 06 '14 at 14:13