Monday, December 24, 2012

Ways to Start Your JBoss Instance

Hello There,

JBoss User's, you must be knowing the ways to start the JBoss Application Server by going into its bin directory and invoking standalone.bat or domain.bat (.sh for Unix)

Recently I found a beautiful utility for starting server which is equivalent to WebLogic's "java weblogic.Server command, however JBoss ones look little different.

For this you need to define the JBOSS_HOME for the Jboss Installation directory in Environment Variables of your local system (Windows), for Unix and Linux Systems you may need to set it and include it PATH variable.

Consider my settings are on Windows and have added the JBOSS_HOME in Environment variables of my Windows 7 Operating System.



After this open a command shell and navigate to your JBoss Installation Directory.



You would see below files in the current directory


C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1>dir
 Volume in drive C is OSDisk
 Volume Serial Number is E604-B574

 Directory of C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1

21/11/2012  22:25    <DIR>          .
21/11/2012  22:25    <DIR>          ..
21/11/2012  22:24    <DIR>          appclient
21/11/2012  22:24    <DIR>          bin
21/11/2012  22:24    <DIR>          bundles
21/11/2012  22:24             2,451 copyright.txt
21/11/2012  22:24    <DIR>          docs
21/11/2012  22:24    <DIR>          domain
21/11/2012  22:24           266,549 jboss-modules.jar
21/11/2012  22:24            26,530 LICENSE.txt
21/11/2012  22:25    <DIR>          modules
21/11/2012  22:24             2,421 README.txt
26/11/2012  15:09    <DIR>          standalone
21/11/2012  22:25    <DIR>          welcome-content
               4 File(s)        297,951 bytes
              10 Dir(s)  157,544,517,632 bytes free

C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1>

Here we will just try to start the standalone serverby invoking the org.jboss.as.standalone you will be able to find all the available modules in C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1\modules\org  so that we can try different tasks to invoke and implement.

Just Invoke the below command : 

java -jar jboss-modules.jar -mp "%JBOSS_HOME%\modules"  org.jboss.as.standalone -Djboss.home.dir="%JBOSS_HOME%" on the command line.

Press Enter


20:37:15,557 INFO  [org.jboss.as.naming] (MSC service thread 1-6) JBAS011802: Starting Naming Service
20:37:15,605 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-4) JBAS015400: Bound mail session [java:jboss/mail/Default]
20:37:16,949 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http--127.0.0.1-8
080
20:37:16,986 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 40) JBAS010403: Deploying JDBC-com
pliant driver class org.h2.Driver (version 1.3)
20:37:20,446 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) JBAS010400: Bound data source [java:jbo
ss/datasources/ExampleDS]
20:37:21,453 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-2) JBoss Web Services - Stack CXF Se
rver 4.0.2.GA
20:37:24,254 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) JBAS015012: Started FileSystemDeploymentServic
e for directory C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1\standalone\deployments
20:37:24,299 INFO  [org.jboss.as.remoting] (MSC service thread 1-5) JBAS017100: Listening on /127.0.0.1:9999
20:37:24,299 INFO  [org.jboss.as.remoting] (MSC service thread 1-8) JBAS017100: Listening on /127.0.0.1:4447
20:37:26,666 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
20:37:26,669 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 32884ms - Started
133 of 208 services (74 services are passive or on-demand)


Let me explain the command.

java -jar jboss-modules.jar -> Here we are executing the jboss-modules.jar this Jar file is needed to bootstrap the application server Kernel based on the JBoss Modules present in Modules folder.

When we invoke the standalone.sh file or the domain.sh file it will internally does the same Job as WebLogic Server is built.

now let us see the complete command line.

java -jar jboss-modules.jar -mp "%JBOSS_HOME%\modules"  org.jboss.as.standalone -Djboss.home.dir="%JBOSS_HOME%"

-mp : its known for Module Path, we are directing the command to get the modules specified in the command from the Directory specified for this parameter.

And we are specifying the JBoss Home Directory to just guide the command at the right location.

Make sure you provide correct details for the path and the variables specified here otherwise you have chances to get the errors like below.


C:\Users\shailesh.dyade\SandBox\ApplicationServers\jboss-as-7.1.1>java -jar jboss-modules.jar -mp "%JBOSS_HOME%\modules" org.jboss.
as.standalone
java.lang.IllegalStateException: JBAS015816: Missing configuration value for: jboss.home.dir
        at org.jboss.as.server.ServerEnvironment.<init>(ServerEnvironment.java:325)
        at org.jboss.as.server.Main.determineEnvironment(Main.java:242)
        at org.jboss.as.server.Main.main(Main.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.jboss.modules.Module.run(Module.java:260)
        at org.jboss.modules.Main.main(Main.java:291)


Reason : If you do not specify the home directory.

Please try by yourself and let me know if you find any difficulties to start the JBoss Server Instance.

Regards
Shailesh Dyade.


Friday, December 21, 2012

Configure Eclipse With JBoss Application Server

Hello There

Today we will look into configuring Eclipse to Work with JBoss Application Server

Prerequisites

1) You need to have Eclipse (Java and J2EE compliant package) copied in your local.
2) Of course JBoss copied in your desired location of your local system.

Next Steps:
==========

Step 1) Start Eclipse and Go to Tools - > Install New Software


Step 2) Click on Add after the Text Box for Work with

You will get a Pop-Up Window as below.

       

Add Name as : JBoss Tools  & Location as below
http://download.jboss.org/jbosstools/updates/development/indigo/

You will see window as ->

Step 3) Wait for Some time after that you will get a big list of JBoss Tools and Utilities which are supported in Eclipse.


From there you need to expand the first one : Abridged JBoss Tools 3.3 and Select the check box of JBossAS Tools 

And Say Next. 

Step 4) Eclipse will check for the Dependencies and report in case if the tools is conflicting with any of the existing modules. 

Step 5) In case if you find any conflicts, its your headache to resolve it :), you will not get any unless you have fresh Eclipse Installation.

Step 6) Proceed for the Installation - Say Next.

Step 7) Do not forget to accept the License Agreement from JBoss.. 


Step 8) Say Finish.!! - You will see the installation has started for Tools you have selected.


     

After Installing You may need restart Eclipse, so the below Pop-up.

      

Step 9) After this you will be able to see JBoss Application Server in the Server Run-time List for Eclipse - Go to Platform Runtime Window and click on new server wizard.



Step 10) To Configure the Server Successfully, Click Next on Above Window and Provide accurate details,  for where your server is installed and the JRE location you would like to use and say Finish.

Step 11) Right Click and Start the Server or You can click on Green Play Button for Starting the Server.

In Console you should notice : 

JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 19726ms - Started 126 of 208 services (7 services failed or missing dependencies, 74 services are passive or on-demand)

Step 12) Time to celebrate now.. your server is started and you will see Fully Loaded Eclipse.. :)




Hope you have liked the Posting, Stay Tuned.!! Lot more to come.

Bye for now.!!

Regards
Shailesh Dyade

Wednesday, December 19, 2012

Developing And Hosting Application on Tomcat Application Server

Hello There,

Have you ever tried developing code and running it over the tomcat being an Administrator of Middleware Technologies, if not you should do it once to learn how things work at very low level, this posting is for start-up Administrators, who would like to learn how the application coding is done, how the applications are deployed and how application servers take the charge.!!

Tomcat as by itself an application server, contains the Web Container and the EJB Container, which host the  JSP, Servlets and EJB Specific Applications.

Here at first place we will configure the Tomcat Application Server with Eclipse IDE and will develop a sample application in Eclipse in deploy it over the Tomcat.

Configuring Tomcat With Eclipse.
============================

Note : As a pre-requisite, you need to have tomcat installed in your local machine ( I am considering it as Windows here)

1) Open Eclipse IDE (Download the Eclipse from this Link)



2) Go to Java EE Perspective as Shown in the picture above at the Right top corner of the Window.

3) You will see Servers tab at the bottom in Platform Runtime Window (To Understand about the Eclipse you need learn about that first ( I am not so good though..;))

4) Click on new server wizard link.

5) You will see a below window popped up in a flash ( Unless you have Core i5 Processor)

6) As I have installed Tomcat 7.x version, I will select the same, you can select your own from the list.

7) Click On Finish ( If you Click on Next, you will have different option to Add resources to the Server environment)

8) You will see the Eclipse window as below

You have a Tomcat Server Configured in the Platform Runtime Window and There is a new Project got created as  "Servers" in Package Explorer Window. If you expand that, it will look like the one below.

You can edit the files and save the files from Eclipse environment from now.

9) Well on other way you have option to start and stop the Tomcat Server from within of Eclipse IDE, Just Right Click on server name and Click Stop/ Start

10) And if you would like to verify you can very well test the page from browser.

http://localhost:9090/ (My Champ (JBoss) is Running on 8080 and asking for the reason to free it up..!!)

There are no files as there are no resources added to the tomcats work directory.


Developing and Deploying Application through Eclipse
==============================================

1) Lets create a Dynamic Web Application in Eclipse.

Go to New -> Dynamic Web Content -> Name Your Application as below - Say Finish

2) You will see the hierarchy of the project as below, its because you have selected the Dynamic Web Content for the project type.

3) Now Create the Web Content - Right Click on WebContent Node -> New -> JSP File

4) After you create this file you will see by default there will be some JSP Specific code will be generated in the file as below.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
##### JSP CODE GOES HERE #####
</body>
</html>

You just need to write your JSP Code between the <body></body> tags.

Copy the below code between <body></body> tags as below.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World</title>
</head>
<body>
<form action="HelloServlet">
Please enter a color <br>
<input type="text" name="color"size="20px">
<input type="submit" value="submit">
</form>
</body>
</html>


Change the title as per your convenience. 

5) If you see, its calling needs a servlet to do get and post the values from JSP's Form which we have see in the above code, lets create it.

6) Right Click on Java Resources : src -> New - Servlet as below.

7) Name your class as HelloWorld as below.

8) Place the below code in the file. ( you may need to remove all other extra things which is already generated, or else you can reuse the same for extra coding purpose ;)


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorld extends HttpServlet {
protected void doGet(HttpServletRequest request, 
     HttpServletResponse response) throws ServletException, IOException 
 {
   // reading the user input
   String color= request.getParameter("color");    
   PrintWriter out = response.getWriter();
    out.println ("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
    out.println("<html>\n");
       out.println("<head> \n"); 
       out.println("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"> \n");
       out.println("<title>Hellow World JSP</title> \n");
       out.println("</head> \n");
       out.println("<body> \n");
       out.println("<font size=\"12px\" color=\"" +color+ "\">"+"Hello World From Shailesh Dyade");
       out.println("</font> \n");
       out.println("</body> \n");
       out.println("</html>");   
 }  
}

Though you can change the code as you wish to develop the application ;)

9) Create web.xml page for accessing these pages - Right Click on WebContent -> New -> File -- File Name : web.xml


















Once created; copy the below contents to the file and Save it.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
  </servlet-mapping>
</web-app>

10) Now you have to test and Run the Application - As we have already configured the Tomcat Server Engine, go to Platform Runtime Window and Right Click on Tomcat Server Name and Go to Add Remove Project.



















11) From Available Projects Add the JSPServletExample Project in the Configured List - Say Finish.

12) Start the Tomcat Server by Right Clicking on it and verify the Tomcat Applications.

13) Try to Access the Page for your Application at 

http://localhost:9090/JSPServletExample/ and verify the file HelloWorld.jsp available in the list.

Now Access the below link or Click on the File HelloWorld.jsp

http://localhost:9090/JSPServletExample/HelloWorld.jsp

14) And See the Page : 














15) Try to Enter a Color in the Text Box and Hit Submit - Here my fav.. Red Wins...!!










Hope you have enjoyed the tutorial, See you later with a new concept and a tutorial soon..!!

Regards
Shailesh Dyade.

How to Fix Memory Leaks In Java

Well Guys, I do not have much to do on this posting as I have nothing to, but you have.!!

Refer the below link to know more about Memory leaks and How to Fix them.

How to Fix Memory Leaks In Java

Regards
Shailesh Dyade