Skip to content

oliviercailloux/samples

Repository files navigation

Samples

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

The sample projects

JavaEE-Servlets

Just one servlet that says “Hello, world.”.

JavaEE-Inject-Servlets

Illustrates CDI and servlets. Just one servlet that says “Hello, world.” thanks to a managed bean, injected into the servlet.

JavaEE-Inject-Servlets-Conversation

Illustrates usage of CDI conversations. (To use it, start by querying ViewConversationServlet, because of a possible Weld bug.)

JavaEE-Inject-Produces-Servlets

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

JavaEE-Inject-Produces-Servlets-JSF

Same as JavaEE-Inject-Produces-Servlets with a supplementary very simple JSF page that calls the producer.

JavaEE-JPA-Inject-Servlets

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.

JavaEE-JPA-Inject-Servlets-JUnit

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.

JavaEE-JPA-JSF

A simple JPA project with two simple JSF pages. Also illustrated: typesafe JPA queries, multi field validation.

JavaSE-JUL-JPA-Hib-H2

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

Other samples

Here are some sources for more samples.

  • wildfly:

    • check out, for example, cdi-injection for a very simple use of CDI.

  • Java EE 7 Samples

  • GlassFish comes with (mostly elaborated) samples (in the samples subdir of GlassFish), also available through svn.

About

Sample projects and configuration files

Resources

License

Stars

Watchers

Forks

Packages

No packages published