advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Use JBoss Cache to Cache and Share Data in Your Enterprise Applications :

Compiling and Building the Code

After the requirements are downloaded and installed on your system, download source code and unzip it anywhere you like. Because you're using Ant as your build tool, almost everything will be done automatica1ly, so before starting Ant, you need to change path names to your own settings. Open the build.xml file with your favorite editor and navigate to the following lines on the top:

...
	<property name="jboss.cfg"		value="default"/>
	<property name="jboss.home"		value="C:/jboss-3.2.7"/>
	<property name="jbosscache.home"	value="C:/x/jboss_cache-1.2.3"/>
	<property name="servletx.path"		value="C:/x/jars/servlet.jar"/>
...
That's the only change you need to make. It's worthwhile to take a closer look:
  • jboss.cfg signifies the configuration in which you will run your JBoss application server. It could be default, all, or minimum. If you haven't made any other changes to your application server configuration, I suggest you to stay with default.
  • jboss.home signifies where your JBoss application server is located.
  • jbosscache.home is the path to the unzipped JBoss Cache. If you unzipped it into the JBossCache-1.2.3 directory, use exactly that name.
  • servletx.path this is the JARs file you use to access javax.servlet.*. In previous versions of JBoss application server, it was included in the libraries. Or you can use JAR from J2EE SDK.
Now, launch the JBoss application server, and compile, build, and deploy the code in it.

The following process is easy—simply type these three commands:

  1. ant: To compile and pack EAR
  2. ant deploy: To deploy the built code
  3. ant clean: To clean all built classes)
If everything's done right, you should see the following screen:

C:\_NR\_articles\docaching\docaching_src>ant
Buildfile: build.xml

compilewar:
     [echo]  **** Compiling Web 1...
    [javac] Compiling 1 source file to C:\_NR\_articles\docaching\docaching_src\build\war1\classes
     [echo]  **** Compiling Web 2...
    [mkdir] Created dir: C:\_NR\_articles\docaching\docaching_src\build\war2\classes
    [javac] Compiling 1 source file to C:\_NR\_articles\docaching\docaching_src\build\war2\classes

war:
     [echo]  **** Packing Web 1...
    [mkdir] Created dir: C:\_NR\_articles\docaching\docaching_src\dist
      [war] Building war: C:\_NR\_articles\docaching\docaching_src\dist\war1.war
     [echo]  **** Packing Web 2...
      [war] Building war: C:\_NR\_articles\docaching\docaching_src\dist\war2.war

sar:
     [echo]  **** Packing Sar...
      [jar] Building jar: C:\_NR\_articles\docaching\docaching_src\dist\service.sar

ear:
      [ear] Building ear: C:\_NR\_articles\docaching\docaching_src\dist\docaching.ear

BUILD SUCCESSFUL
Total time: 4 seconds
C:\_NR\_articles\docaching\docaching_src>ant deploy
Buildfile: build.xml

deploy:
     [echo]  **** Deploying...
     [copy] Copying 1 file to C:\jboss-3.2.7\server\default\deploy

BUILD SUCCESSFUL
Total time: 1 second
C:\_NR\_articles\docaching\docaching_src>ant clean
Buildfile: build.xml

clean:
   [delete] Deleting directory C:\_NR\_articles\docaching\docaching_src\build
   [delete] Deleting directory C:\_NR\_articles\docaching\docaching_src\dist

BUILD SUCCESSFUL
Total time: 1 second
And in your JBoss application logs, you should see:

...
12:31:14,421 INFO  [Server] JBoss (MX MicroKernel) [3.2.7 (build: CVSTag=JBoss_3_2_7
date=200501280217)] Started in 16s:938ms
12:35:09,703 INFO  [EARDeployer] Init J2EE application:
file:/C:/jboss-3.2.7/server/default/deploy/docaching.ear
12:35:13,390 WARN  [TreeCache] No transaction manager lookup class has been defined.
Transactions cannot be used
12:35:14,609 INFO  [TreeCache] interceptor chain is:
class org.jboss.cache.interceptors.CallInterceptor
class org.jboss.cache.interceptors.LockInterceptor
class org.jboss.cache.interceptors.UnlockInterceptor
12:35:14,609 INFO  [TreeCache] cache mode is local, will not create the channel
12:35:14,640 INFO  [TomcatDeployer] deploy, ctxPath=/webapp1,
warUrl=file:/C:/jboss-3.2.7/server/default/tmp/deploy/tmp21186docaching.ear-contents/war1.war/
12:35:14,843 INFO  [TomcatDeployer] deploy, ctxPath=/webapp2,
warUrl=file:/C:/jboss-3.2.7/server/default/tmp/deploy/tmp21186docaching.ear-contents/war2.war/
12:35:15,375 INFO  [EARDeployer] Started J2EE application:
file:/C:/jboss-3.2.7/server/default/deploy/docaching.ear

Time for Testing

To test this application, type http://localhost:8080/webapp1/hi in your browser window. This takes you to the servlet of the first Web application. Of course, before it was deployed nothing was in cache, so it says that it fetched 'null' and that is correct. However, being a nice servlet, it puts its own greeting into cache. You can reload the page and see that servlet "sees" its own greeting.

To check if the second Web application is able to see greeting from the first Web application, go to http://localhost:8080/webapp2/hi. Not only has it placed its own greeting, if you will get back to first application, you will see it is shown there as well. This shared data is cached!

Use Caching Wisely

This tutorial shows an easy example of caching which can be used partially or completely as a solution for your real-life applications. But remember that it's not a "use-wherever-possible" solution. Also remember: do not overload your application if that's not what you really need. Sometimes even caching can be an overkill.

Resources

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs