Advance Java‎ > ‎

JBoss Web Server

  Install JBoss Web Server

          
  • Unzip downloaded JBoss file into c:\program files\java folder.  It will create c:\program files\java\jboss-as-7.1.1 Folder
              
           

  • Unzipped JBoss directory will have following folder structure.  It is important that you should know what each directory does:
            

    

   Directory Structure of JBoss Server 

        

    Standalone Directory Structure

             
           

     Domain Directory Structure

     
          
    
  • Make sure that JAVA_HOME environment variable point to your JDK home director. Please refer J2EE Environment Setup
  • Congratulation now your server is ready to start.
  • Go to c:\program files\java\jboss-as-7.1.1\bin folder and run standalone.bat file. A command line window will be opened, check the below image
           
         
          
          
  • Now time to test your server. Open a browser and enter URL http://localhost:8080. If a page is displayed with following logo then your server is successfully started.
                
          


       If server is not yet started then check your JAVA_HOME environment variable.

    Structure of a Web Application

       A web application is deployed in the \server\default\deploy folder. One web application will have below director structure.

       

    Steps to Deploy a Web Application

       Before you assemble the application components, you must define the directory structure for the application. To do so:

  1.    Create a root directory with an appropriate name for the application, say \onlineresult inside .\jboss-4.0.4\server\default\deploy folder
  2.     In the root directory \onlineresult, create the following directory structure.
    • \onlineresult :
      • Contains JSP, HTML, JavaScript, Images, Applet files
      • \WEB-INF
        • web.xml : application configuration file
        • \classes : contains all compiled servlets and java classes
        • \lib : contains library jars like database drivers
  3.  Now start your JBoss server.
  4.  Open a browser and enter url http://localhost:8080/onlineresult/index.html. You will see your page.

      A special directory exists within the application hierarchy named “WEB-INF”. It is important to note that the WEB-INF directory is not
      part of the public document tree of the application. A browser can not access any document from URL that exists within WEB-INF. 

        WEB-INF contains

  • /WEB-INF/web.xml  deployment descriptor, configures application.
  • /WEB-INF/classes/  directory for servlet and utility classes.  The classes in this directory are used by the application class loader to load classes from.
  • /WEB-INF/libcontains library jars like database driver.  All such archive files are used by the web application class loader to load classes from.

Creating a Data Source for the External Database

JBoss AS connects to relational databases via data sources. These data source definitions can be found in the jboss-as/server/production/deploy directory. The data source definitions are deployable just like WAR and EAR files. The data source files can be recognized by looking for the XML files that end in *-ds.xml.

The data source definition files for all supported external databases can be found in the jboss-as/docs/examples/jca directory.

  • MySQL: mysql-ds.xml

  • PostgreSQL: postgres-ds.xml

  • Oracle: oracle-ds.xml

  • DB2: db2-ds.xml

  • Sybase: sybase-ds.xml

  • MS SQL Server: mssql-ds.xml

The following code snippet shows the mysql-ds.xml file as an example. All the other *-ds.xml files are very similiar. You will need to change the connection-url, as well as the user-name / password, to fit your own database server installation.

<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/jboss</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>jbossuser</user-name>
<password>jbosspass</password>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker
</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool -
MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>

</datasources>

Once you customized the *-ds.xml file to connect to your external database, you need to copy it to the jboss-as/server/production/deploy directory. The database connection is now available through the JNDI name specified in the *-ds.xml file.


FAQ

Q: Where do you deploy your application at JBoss?
Ans: We deploy web application as war or exploded format in ..\server\default\deploy folder.

Q: How do you configure data connection pool in JBoss?
Ans:  Using mysql-ds.xml file, keep in the deploy folder.  See above 'Creating a DataSource for the External Database'

Q: What is the default port of JBoss server ?
Ans: 8080.

Q: How to start and stop JBoss server?
Ans: Using .bin\standalone.bat  and .\bin\shutdown.bat.

Q: What is the deployment folder structure of a web application in JBoss/Tomcat Server?
Ans: See above 'Structure of Web Application'.

Q: How do you integrate JBoss with Tomcat?
Ans:  Tomcat comes with JBoss as a deployable service in jbossweb-tomcat-5.0.sar folder.

Two files need to be changed to configure Tomcat with JBoss.
(1)  Configure org.jboss.web.tomcat.tc5.Tomcat MBean entry into  ./jbossweb-tomcat-5.0.sar/META-INF/jboss-service.xml file.
(2)  Configure ./jbossweb-tomcat-5.0.sar/server.xml

More info >> http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch9.chapt.html

Q: How can you change the default port of JBoss server?
Ans: Replace 8080 by your desired port in ./jbossweb-tomcat-5.0.sar/server.xml file.

<<Back
Comments