Here are some samples about Java EE technologies (JPA in Java SE is covered as well). They serve two purposes:
-
give a head start (if you want a correctly configured project as a basis for work); and
-
illustrate “best” practices in concrete, simple cases.
To access these samples with Eclipse, I recommend to first git clone this repository, then, from Eclipse, use Import… Existing Projects
.
All projects use Maven and are designed for maximal compatibility. They should run on any Java EE 7 server. (Tested with GlassFish only.)
Illustrates CDI and servlets. Just one servlet that says “Hello, world.” thanks to a managed bean, injected into the servlet.
Illustrates usage of CDI conversations. (To use it, start by querying ViewConversationServlet, because of a possible Weld bug.)
Shows usage of CDI (Injection of managed beans) and producers together with simple servlets. This will be useful only if you want to know about producers. Otherwise, check a simpler CDI sample (see Other samples).
-
The
advanced
package illustrates dynamic instance creation. That advanced servlet also has a question that you might want to solve as an exercice (look at the Javadoc).
Same as JavaEE-Inject-Produces-Servlets with a supplementary very simple JSF page that calls the producer.
A simple JPA project, using a single entity, simple CDI managed beans and two simple servlets (posting items and getting items).
-
The
advanced
package illustrates different transaction management approaches.
Illustrates (the awkwardness of) JUnit-testing servlets that use CDI. This sample uses standalone Weld. Not recommended: see Weld-SE in my Best practices folder.
A simple JPA project with two simple JSF pages. Also illustrated: typesafe JPA queries, multi field validation.
A simple JavaSE project featuring JPA, starring Hibernate as a JPA provider and H2 as a DB provider. This sample project uses JUL as a logger (contradicting my own preference).
Here are some sources for more samples.
-
-
check out, for example, cdi-injection for a very simple use of CDI.
-
-
GlassFish comes with (mostly elaborated) samples (in the
samples
subdir of GlassFish), also available through svn.