Tags

GlassFish

CLASSE has migrated most production Java EE applications to Payara from Glassfish. For instructions on using Payara, please see PayaraServer.

Many CLASSE users and groups are using the NetBeans IDE and GlassFish Enterprise Server for developing and deploying java applications.

Two production GlassFish servers are currently available. One for general CLASSE applications, and one for CESR specific applications.

Getting Started

Use the following procedure from any CLASSE Linux computer for creating an initial environment for developing and testing java applications.
  1. start the NetBeans IDE using /nfs/opt/netbeans/bin/netbeans
  2. click on Window in toolbar and select Services
  3. right-click on Servers and choose Add Server ...
    1. Choose GlassFish Server under Server, and name the server accordingly. Click on Next.
    2. "Installation Location:" should be /nfs/classe/glassfish
    3. Select Local Domain, agree to the license agreement
    4. Click on Next.
    5. Enter details for local domain:
      • under Domain: type in a new folder on a centrally-accessible NFS filesystem related to the project you are working on (note that the directory must not already exist or you will get an error).
      • If desired, choose a username and password to secure your personal domain.
      • click "Finish"

Databases

Database Connections

If you require a MySQL database for your application, submit a ServiceRequest describing what you would like to use the database for. Please see JDBCResourcesInGlassFish for instructions on configuring NetBeans / glassfish for use with a database.

Relational Databases

Cornell's Computer Science Department has an introductory database course, CS 4320/5320, that covers the basics for understanding relational databases. It does touch on some underlying mathematical priniciples, but it aims to initially provide the building blocks needed to use relational databases. For example, it covers how to create tables and then link them with primary and foreign keys.

As of Fall 2018, the entire set of Fall 2017 lectures for this course is available on Cornell's Video On Demand site.

The first three or four lectures cover the essentials required for setting up and using a relational database. They'll introduce you to tables, columns, rows, primary keys, and foreign keys. Databases have other more complex features, but those are the main building blocks needed to create and use a relational database.

Deploying applications

Once you are ready for others to view and test your application, please submit a ServiceRequest for instructions on where to deploy your application on our centrally available glassfish servers.

Best Practices

Adhering to the following guidelines will help ensure your code is developed in a manner consistent with the rest of CLASSE's java web applications.

  • Use ApacheNetBeans as the IDE.
  • Keep a model-view-controller approach.
    • the ApacheNetBeans auto-generator helps to maintain this approach
    • Entity and Facade classes handle the model
    • Controller classes handle the controller
    • XHTML pages handle the view
  • The following tutorials may be helpful when just starting out. https://netbeans.org/kb/trails/java-ee.html
    • This tutorial requires access to a MySQL database. Please request a test database from service-lepp@cornell.edu if you are developing on a LEPP Linux machine. Alternatively if you are developing on a personally-owned computer, you also have the option of installing the MySQL database on your personal computer.
  • Use Java Server Faces 2.x (JSF) for the web interface.
  • Use PrimeFaces an open-source JSF framework for added functionality.
  • Use OmniFaces JSF 2 utility for added functionality (Primefaces will probably be enough; you can wait to add Omnifaces as the need arises)
  • Oracle’s Java EE 7 Tutorial - this can explain all of the annotations you see in the code, as well as anything else related to Java EE. This is the official Java EE document.
  • As of Summer 2018, there are a lot of Java changes afoot, like more regular but not necessarily supported releases of Java SE, Java EE changing to Jakarta EE and being taken over by the Eclipse Foundation, and NetBeans being taken over by Apache. Given all of the flux, it is recommended for now to stick with our current stack of Java SE 8, Java EE 7, and Glassfish 4. But we should upgrade once all of the new technology settles down.

using ViewScoped instead of SessionScoped

One other note I’ll add about the app you’re creating is that while it is nice that NetBeans creates those CRUD pages for you, they’re a bit dated and aren’t really doing things the “right” way. In particular the “backing beans” (i.e. the controller classes) are all Session Scoped. The upside is that what they create works. The downside is doing it the “right” way means basically abandoning the XHTML and controller classes they create for you.

If you look at the controllers in the other busoff and chess inventory projects you’ll see that controllers are View Scoped by the @ViewScoped annotation (note the import name for viewscoped should be javax.faces.view.ViewScoped; there are actually two possibilities for this name, and the other one won’t work!). This annotation means that every time a page that uses that backing bean is called a fresh instance of that controller object will be created. If you noticed, there is no place in the code where objects of those classes are constructed. The annotation tells the Glassfish container to do the constructing, which is how the XHTML pages can access them.

To oversimplify a bit, I’ll just say using @ViewScoped ensures you are going to see what you are expecting to see (viewing a piece of equipment, an inventory item, etc.). With session scoped backing beans, in effect pages appear to get cached in the browser, requiring users to reload pages in order to see changes they’ve made to the database, etc. Basically, the only classes that should be session scoped are classes that deal with users as the session scope covers the time between the user visiting the site to the user quitting the browser or 30 minutes, whichever comes first (see the session-timeout tag in web.xml).

Getting Help

If you Google questions about JSF and Java EE, you will likely come across answers written by Bauke Scholtz (aka BalusC) on StackOverflow. He is a JSF expert and has written a book about it, called The Definitive Guide to JSF in Java EE 8: Building Web Applications with JavaServer Faces. If you see he answered the question, you can trust his answer is correct and authorative. You can also go directly to his StackOverflow page where he provides introductory JSF information.

The JSF book is available as a free download from Springer Link, if you access the URL from a Cornell network: https://link.springer.com/book/10.1007/978-1-4842-3387-0 (last accessed: 12/17/18).

CESR Java Development Documenation

CESR maintains their own NetBeans release and documentation. While aspects of their documentation is CESR specific, this could be a great resource for anyone just getting started with NetBeans or Java development.

https://cesrwww.lepp.cornell.edu/wiki/CESR/ControlCodeJavaDeveloperInfo
Topic revision: r22 - 30 Jun 2021, AdminMichaelRyan
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CLASSE Wiki? Send feedback