Enterprise Application Development with NetBeans IDE
Authors: V. Prabakar, Dr. B.V. Kumar, Prakash Narayan and PCM Reddy
The NetBeans Integrated Development Environment (IDE) is one solution for all your Java development needs. It is ideal for Java programmers - not just a generic environment that tries to provide a little something for everyone. In this white paper we would like to share a IDE success story from Infosys (www.infosys.com), a global consulting and IT Services company, on how the NetBeans IDE helped them to turn a concept demo into a real life enterprise application.
Here is a quote from the Infosys Principal Architect, “It started with an intention to build a demo application using the NetBeans IDE for internal training in our organization. But as we added features into the application – it was remarkably easy, thanks to the new and intuitive features in both Java EE 5 and the NetBeans IDE – we only ended up being thirsty to add more and more functionality into our real application”.
Enterprise Asset Management is vast and spans inventory management, supplier management, CRM solutions, billing solutions, work flow management, resource tracking, order management, and synchronization of various artifacts across factory premises, warehouses and sales desks. The team was asked to concentrate on the very basics, which included asset management, asset tracking, order management, inventory management and a simple and tailor-made customer relationship management implementation. The figure below shows the overall system use case.
Asset Management use case
Why NetBeans IDE?
The NetBeans IDE is a robust, free, open source Java IDE that provides the developer with everything they need to create cross-platform desktop, web and mobile applications straight out of the box. It comes with the following features:
Supported Java technologies :
Other Key IDE features :
Enterprise Application Development Experience:
NetBeans IDE provides excellent out-of-the-box experience from simple Java SE/EE development to enterprise application programming. The NetBeans IDE includes programmer-friendly features like annotations, code completion, refactoring, dependency injection in Java SE 5 and powerful Java Persistence API in EJB 3.0. The UML functionality in NetBeans IDE helps to reverse engineer Java code and apply design patterns to Java code.
The Enterprise Asset Management The application consists of a web interface to manage assets and purchase orders. Now we will see how this application is developed using NetBeans IDE.
Create Java Application:
In the IDE's File Menu, choose New Project. In the category “General”, select “Java Application”. Click on Next and set Project Name to “EAM-Asset”. We will add persistent classes for Asset. Similarly Create Java Project “EAM-PO.” This will be used for purchase order persistent classes.
NetBeans IDE has an easy to use interface for databases. JavaDB is installed as a part of Sun Java System Application server or GlassFish Server installation. The following picture shows database integration in NetBeans IDE. It is easy to configure other JDBC drivers/servers.
EAM-Asset application (Persistence classes from database tables)
Create a Java Application “EAM-Asset”. Add “Entity class from database”. The Entity Class wizard connects to the Java DB server and fetches the tables list from the database. In this case, we are using “MASTERASSETTABLE” as shown below.
This wizard allows users to edit the entity class's name. For example “Masterassettable” can be changed to “Asset”.
In the same panel there is a button for creating a “Persistence Unit” which will be created and added to the Web application automatically.
Adding Annotations to Asset class
Once the “Asset” class is created, we added the following inheritance strategy and discriminator in the code.
Code Completion Support for Annotations:
NetBeans IDE provides full code completion support for annotations and attributes, which means less compilation errors and time saving. See the following picture for code completion for Java persistence annotations.
Code completion support for attributes in Annotations:
We use the “HardDrive” and “Monitor” classes by extending the Asset class. Similarly, we created the EAM-PO (Enterprise Asset Manager Purchase Order) application, using "LineItems" and "PurchaseOrder" tables as we discussed earlier.
We also added the following classes to the EAM-PO application.
NamedQueries are generated Automatically:
We added the following custom NamedQuery to the existing NamedQueries list in PurchaseOrder.java.
@NamedQuery(name = "PurchaseOrder.findByShipment", query = "SELECT m FROM PurchaseOrder m WHERE m.shippingAddress = :shipment")
Web interface for asset management application.
We created a Web Application named “EAM-AsserMgmt-web” and added the following servlets:
We added a JDBC resource and called it "jdbc/myDatasource" using existing the DataBase Connection Pool, or the user can create a new connection pool.
Adding JDBC Resource:
Verification of JDBC Resources:
Once the JDBC Pool and Resource are registered with the application server, they can be verified in the IDE's Runtime Tab.
Adding a persistence unit was never an easy task, but with the IDE's project wizard it is simplified now.
Adding PersistenceContext to Servlet :
We selected each of the servlets and added @PersistenceContext, @Resources.
This will automatically add a “persists” method as shown below.
“AssertValidation.js” and “commonstyle.css” are added to the application.
Then we implemented the required logic in the following servlets.
Fix Imports Automatically
Whenever new classes are added to servlets including annotations, the IDE fixes imports automatically.
Add Try-Catch Automatically
If there are any lines of code that need to be wrapped by a try-catch-block, the NetBeans editor does this automatically.
Refactoring support in NetBeans IDE
The user can make use of various IDE's refactoring features to manage code.
For instance, finding the usage of a variable in the NetBeans editor, or finding any unused variables in the code.
Visually Editing Web.xml
The web deployment descriptor provides a visual representation of “web.xml”. It is easy to navigate between different sections of web.xml.
Setting Breakpoints in the Code
Setting breakpoints in the code and debugging the application is very simple in NetBeans IDE.
We added the following servlets to EAM-PO-web application.
Then we added the JDBC resource, @PersistenceContext and @Resources in Servlets, and implemented the business logic in the servlets.
Creating UML Model from Java Classes
The NetBeans UML plugin was used to do analysis and round-trip engineering on the Java Code. NetBeans UML offers several enterprise class features.
Executing the application
After we cleaned, built and deployed both the web applications, we selected each webapplication and ran it from the IDE. The welcome page of each webapplication is launched in the webbrowser.
Developing enterprise scale applications was never so simple, definitely. NetBeans IDE and the NetBeans Packs empower enterprise application developers to reduce the complexity and increase productivity. Several scripting modules are being added to NetBeans IDE which enables it to serve broader development needs. NetBeans IDE makes enterprise development much simpler and much less boilerplate.
Resources for further reading