Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about creating a jar file with eclipse

 
joe black
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to design a layered application, and I am creating a workspace for each layer.

I first started with the persistence layer. It uses hibernate, and now I want to create a jar file so that the other layers can use it as a dependency.

I placed all the hibernate jars in src/lib, and all source files are under src/java. However, after creating a jar using export->jar file, and adding it to the other project's build path, it cannot find any of the hibernate stuff.

I assume I am not understanding how to use the java build path correctly.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you add the JARs into your project properties ?
RightClick your project -> Properties -> Java Build Path -> Libraries
 
joe black
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the hibernate jars to the project properties of the persistence layer. Do I need to add the hibernate jars to the other projects as well?
 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. How should Eclipse know that you intended for there to be a relationship between the two projects?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you need to add the reference to external jars wherever you use them.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't use the jar for the other projects, but let them depend directly on the persistence project. The persistence project can then export the dependencies on hibernate et al.

This way it's easier to test how the projects work together and it enables easy cross-project refactorings, while still making sure that you don't get any undesired code dependencies.

You can still use the different jar files for distribution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic