Using Oracle WebLogic 12c with NetBeans IDE

by Markus Eisele

Your head-start to using the latest NetBeans IDE with Oracle WebLogic Server

April 2014

Downloads
download-icon13-1Java SE 7
download-icon13-1Oracle WebLogic
download-icon13-1Netbeans

Introduction

NetBeans is a free (CDDL/GPL licensed) integrated development environment (IDE) for Java applications. It has recently been released as version 8.0 and is the first choice for developers when it comes to support for the latest Java platform editions. It provides extensive tooling for a broad range of technologies, ranging from Java desktop and mobile applications to web applications built with the latest HTML5 and JavaScript frameworks and Java EE backends. NetBeans always strives to provide the most up-to-date tooling far ahead of other IDEs, and, as such, has been around with betas and release candidates supporting Java 8, Java EE 7 and JavaFX 2. Having a very early chance to test drive all the latest specifications around the different Java platforms, NetBeans is a great choice for developing with Oracle products. The Java EE edition comes bundled with GlassFish Open Source Edition 4.0 and provides all the needed integrations for the latest WebLogic 12c. This article walks you through installing and configuring all necessary components, and helps you with getting a first tiny Java EE up and running.

Preparation

Getting started with NetBeans and WebLogic requires some installation and configuration. First, download and install the latest Java Platform Development Kit (JDK) 7u51. Make sure to pick the right version for your development environment. It's always good to keep an eye on the latest Java SE and SDK downloads, as patches improve security and stability. This article assumes you're working on Windows, but it shouldn't be too difficult to anticipate the necessary changes for Linux-based systems.

After installing the JDK you should have everything in a location similar to D:\jdk1.7.0_51. This location will be called JAVA_HOME from now on. Now it's time to download and install NetBeans IDE 8.0.

The websites offer five different downloads (Java SE, Java EE, C/C++, HTML5 and PHP), which differ in features and functionality. The Java EE version (with estimated 191MB size) is what helps us with developing Java EE applications. After you download the executable, all you have to do is to start the installation. Once the initial setup is finished, decide if you want Tomcat or GlassFish, or both, to be installed additionally. While GlassFish 4 offers the latest Java EE 7 technologies and Tomcat is a very lightweight Servlet container, neither are required in what's to come, and you can uncheck the boxes if you want to speed up the installation process.

Finish everything by clicking your way through the following license acceptance screens, set the desired installation paths and point the installer to the location where you installed the JDK.

NetBeans

Figure 1: NetBeans Installer

The summary page displays all decisions at a glance. If you want to be informed about component updates, check the relevant box. All that's now left to do is to watch the installation progress, which should take 2-5 minutes, depending on your system configuration. The last configuration screen politely asks you to contribute to the NetBeans project by providing anonymous usage data. You're all done with a last click on Finish. For your convenience, find shortcuts on the desktop or the Windows start menu.

One last component is waiting to be installed: download the latest version of Oracle WebLogic 12c (12.1.2).

Now, you have to accept another license agreement. WebLogic Server is provided for developers under the OTN Free Developer License Agreement. Similar to NetBeans, there are different version and platform downloads available. Pick the one that best suits your needs. The generic installer and the zip distribution do not include a JVM/JDK, so get started using the zip distribution with the smallest footprint (182MB). The distribution is suitable for Windows x86, Linux x86 and Mac OS X. Almost any Oracle product download requires you to sign in with your Oracle SSO account before receiving the download.

The file is called wls1212_dev.zip and should be put into a location of your choice (e.g., D:\Oracle) and unzipped. The newly created folder wls12120 is called MW_HOME. Things are going to get a bit more command-line oriented from now on (just the way developers like it).

Open a shell and set it up by defining two environment variables:





set JAVA_HOME=D:\jdk1.7.0_51
set MW_HOME=D:\Oracle\wls12120



After you have done this, run the installation configuration script configure.cmd in the MW_HOME directory. This is a one-time thing to do and basically unpacks the contained jar files into a usable format. The script finishes with a short notification ("Your environment has been set") and asks if it should also configure your first domain. We're taking things easy here, so just answer "Y" for "yes." Magic continues to happen, and you're prompted to enter an admin username and a password (e.g., user:system / password:weblogic1). Only seconds after confirming both, you witness the start of the newly created domain. Take one of the supported web browsers (e.g., Chrome) and give it a try at http://localhost:7001/console. First-time access automatically deploys the console-web-application, which lets you manage your domain.

WebLogic

Figure 2: WebLogic Console

We're done with installing and configuring for now. Now it's finally time to get your hands dirty with NetBeans and implement a small example application.

Explore NetBeans 8 and Add WebLogic

NetBeans IDE delivers excellent support for developing Web and server-side applications that use the Java EE platform. IDE support has been developed in close cooperation with the Java EE and GlassFish teams to provide the tightest integration and easiest possible use of the Java EE specification. Consequently, if you are new to the Java EE specification and framework, using NetBeans IDE is the best way to quickly learn and become productive in Java EE programming. Once you start working with the IDE, you'll see that it is basically separated into two areas: the navigator area and the editor area.

NetBeans IDE

Figure 3: Basic NetBeans IDE Layout

The navigator area displays the Services tab, which highlights the GlassFish 4 server that I previously configured. Now it's time to configure the newly created WebLogic 12c domain and add it to NetBeans.

Right click the Servers node and select Add Server. This opens a wizard that guides you through the following process and collects all the needed information.

Select Oracle WebLogic Server and (optionally) change the name to anything you want. I'll take the proposed name and click Next.

The wizard now wants you to specify the server location. Enter MW_HOME/wlserver (e.g., D:\Oracle\wls12120\wlserver) and click Next.

One final step requires you to enter the instance properties. NetBeans automatically tries to find the available domains in the server location and recommends the one domain we created. Enter the username/password we assigned during domain creation and click Next.

The Servers node now shows you the newly created instance and, because it started after we first created the domain, it shows a green arrow next to the red logo. You can browse through the installed applications, modules and resources while the server is started.

A right click on the server node brings up a context menu with all the actions you can execute directly from within the IDE. Besides starting and stopping the server both in production and debug mode, you can also quickly jump to the admin console or show the Server Log in a NetBeans output window.


NetBeans WebLogic Server

Figure 4: NetBeans WebLogic Server Log Output

Congratulations! You've set up and configured everything. It's time to start your first Java EE project and deploy it to WebLogic.

NetBeans Services

Figure 5: NetBeans "Services" Tab with Configured WebLogic and GlassFish

Hello World Project

The first thing to do is to switch the navigator view from Services to Projects. Right click in the empty area and select New project. A wizard will guide you through everything you need to get started. In fact, you can select from many different project types and modules. Let's get started with a simple Java EE 6 Web Application. In the wizard, select the category Java Web and Web Application in the projects. This creates an empty Web application in a standard IDE project. A standard project uses an IDE-generated build script to build, run, and debug your project.

Clicking Next lets you change the name and location of your project (e.g., HelloWebLogic).

Another Next click takes you to the server settings. Select Oracle WebLogic Server and Java EE 6 Web. Everything else stays on the defaults. A last click on "Finish" starts the project generation and the index.jsp is automatically opened in the editor view.

If you now right click the project in the navigator and select Run, it is automatically deployed to the local WebLogic instance. A window or tab of your default browser opens automatically pointing to http://localhost:7001/HelloWebLogic/, which generates a simple "Hello World!" output. Feel free to go back to NetBeans and modify the word "World" to "WebLogic" and hit Save. NetBeans automatically deploys the change and a simple refresh in the browser window shows the updated page.

You're not limited to having just a single JSP in your application. NetBeans supports you with all you need to build full-blown Java EE applications. Take advantage of all the assistants and wizards for automatically configuring your application. A more complete list of available features can be found on the NetBeans.org website.

Remote Deployment

Instead of using the local WebLogic installation, you might want to deploy your application to a remote machine. NetBeans' excellent Maven 3 support, which ships with the default IDE installation together with the WebLogic Maven plugin, can do that for you. The NetBeans IDE automatically recognizes any existing Apache Maven project and you can simply open it. Further, the IDE also offers a way to create new Maven-based projects from scratch. The projects are generated using the maven-archetype-plugin. The remote deployment can then be added to the Maven project via the WebLogic Maven Plugin (see Using the WebLogic Development Maven Plug-In).

After you have completed the steps necessary to locally install the WebLogic Maven Plugin on your developer machine, you can just add the configuration below to the projects pom.xml file. Beside adding the plugin dependency, the configuration maps the required plug-in goals to the Maven lifecycle phases. We're basically interested in the deploy goal, which is bound to Maven's pre-integration-test phase. Instead of using 127.0.0.1 as part of the admin-url, you can use any remote machine name or IP address.






  
    com.oracle.weblogic
    weblogic-server-pom
    12.1.2-0-0
    pom
    provided
  





 com.oracle.weblogic
 weblogic-maven-plugin
 12.1.2-0-0
   
     D:/Oracle/wls12120
   
   

     
       wls-deploy
       pre-integration-test
       
         deploy
       
   

     t3://127.0.0.1:7001
     system
     weblogic1

${project.build.directory}/${project.build.finalName}.${project.packaging}

     myserver
     true
     ${project.build.finalName}
   
  
 




Validate that everything is working as it should by issuing the following command at the command-line:





com.oracle.weblogic:weblogic-maven-plugin:help



It should output all the available plug-in goals:





[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloWorld 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- weblogic-maven-plugin:12.1.2-0-0:help (default-cli) @ HelloWorld ---
The following are the goals available currently in Maven
appc
create-domain
deploy
distribute-app
help
install
list-apps
redeploy
start-app
start-server
stop-app
stop-server
undeploy
uninstall
update-app
version
wlst
ws-clientgen
ws-jwsc
ws-wsdlc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.056s
[INFO] Finished at: Tue Mar 11 08:46:47 CET 2014
[INFO] Final Memory: 8M/222M
[INFO] ------------------------------------------------------------------------



Notice that you can use the plugin to incorporate many different tasks into your build. In this example, we're just deploying the little example application remotely by installing the application with Maven.

In the above pom, the WebLogic Maven plugin was directly bound to the default profile; you can execute it by issuing the following command at the command line:





mvn install



As an alternative, you can right-click the project in NetBeans and then select Build. This is probably not what you desire, because you might want to actively decide when you are deploying the app to the server. By moving the plugin configuration around to a section—





<profiles>
    <profile>  
	<id>deploy</id>  
	<build>        
	<pluginManagement>         
	<plugins>



—you can take full advantage of the Maven integration with NetBeans and use the profile switch to decide whether to deploy (or not) by simply selecting the appropriate profile.

Figure 6: NetBeans Maven Profile Switch

The output during the execution (via either NetBeans or command-line) looks like this:





[INFO] --- weblogic-maven-plugin:12.1.2-0-0:deploy (wls-deploy) @ HelloWorld ---

[INFO] Command flags are: -noexit -adminurl t3://127.0.0.1:7001 -deploy -user sy
stem -password ******* -name HelloWorld-1.0-SNAPSHOT -source 
D:\HelloWorld\target\HelloWorld-1.0-SNAPSHOT.war -targets myser
ver -verbose
weblogic.Deployer invoked with options:  -noexit -adminurl t3://127.0.0.1:7001 -
deploy -user system -name HelloWorld-1.0-SNAPSHOT -source 
D:\article\HelloWorld\target\HelloWorld-1.0-SNAPSHOT.war -targets myserver
 -verbose
<11.03.2014 09:00 Uhr MEZ>    
Task 10 initiated: [Deployer:149026]deploy application HelloWorld-1.0-SNAPSHOT on myserver.
Task 10 completed: [Deployer:149026]deploy application HelloWorld-1.0-SNAPSHOT on myserver.
Target state: deploy completed on Server myserver

Target Assignments:
+ HelloWorld-1.0-SNAPSHOT  myserver
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ HelloWorld ---

[INFO] Installing D:\HelloWorld\target\HelloWorld-1.0-SNAPSHOT.war to 
D:\.m2\repository\net\eisele\HelloWorld\1.0-SNAPSHOT\HelloWorld-1.0-SNAPSHOT.war
[INFO] Installing D:\article\HelloWorld\pom.xml to D
:\.m2\repository\net\eisele\HelloWorld\1.0-SNAPSHOT\HelloWorld-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.402s
[INFO] Finished at: Tue Mar 11 09:00:23 CET 2014
[INFO] Final Memory: 18M/349M
[INFO] ------------------------------------------------------------------------



Your application is now ready at http://127.0.0.1:7001/HelloWorld/ and you can, of course, verify it via the WebLogic console.

WebLogic

Figure 7: WebLogic Console Screen After Successful Remote Deployment

Conclusion

NetBeans and WebLogic Server are very tightly integrated and allow a seamless development while providing the latest technology support. Together with the additional Maven support from WebLogic, you can deploy your applications to a local and to a remote instance.

References

About the Author

Markus Eisele is a software architect, developer and consultant. He works daily with customers and projects dealing with enterprise-level Java and infrastructures, including the Java platform and various Web-related technologies on a variety of platforms using products from different vendors. An expert in Java EE Servers, Markus is a Java Champion, a member of the Java EE 7 expert group, and is a frequent speaker at industry conferences.