<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>keyboardsamurais.de &#187; Tutorial</title>
	<atom:link href="http://keyboardsamurais.de/category/Tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://keyboardsamurais.de</link>
	<description>thoughts on software development, warts and all...</description>
	<lastBuildDate>Sun, 19 Jun 2011 12:36:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Tutorial: Deployment of client side Java or Eclipse/SWT Applications on Windows</title>
		<link>http://keyboardsamurais.de/2004/05/16/tutorial_deployment_of_client_side_java_or_eclipseswt_applications_on_windows/</link>
		<comments>http://keyboardsamurais.de/2004/05/16/tutorial_deployment_of_client_side_java_or_eclipseswt_applications_on_windows/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>Toni</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>When building a client side Java application, with whatever GUI Framework happens to be your favourite one (AWT, Swing, SWT - just to name the obvious triplet), at some point you really have got to ask yourself what would be the best way to distribute your app, without causing the end-user too much pain. </p>

<p>I think that most people would agree that customer acceptance depends to a large extent on the first impression of the user with the particular product. The first contact with your software however, typically is the installation procedure. With java software and the advent of so called "Platform independent" solutions various attempts to address installation facilities have been tried, but just too often, java coders tend to neglect this duty shamefully. Pretty often you find yourself with some classes and jar files you need to copy all over your system, add extensions to your classpath and finally launch the app from the command line via :<code>java classname</code> just to watch it fail a dozen times before you discover that you forgot to add the <code>-Djava.library.path</code> property to the command line (as stated in the readme.txt at line 1846).</p><p><b>The Installer</b><br />
Windows users can be very choosey about standardized installation procedures, thus I would recommend using a native Windows Installer like the <a href="http://nsis.sourceforge.net/home/">Nullsoft Install System</a> to create an installer (i.e. a <code>Setup.exe</code>) for your application that can be installed and uninstalled properly in a standard, Windows way<sup>tm</sup>. NSIS offers a pretty cool, powerful macro language for installers that you fortunately don't really have to learn to create your typical basic installer. For the average installer it is sufficient to use the really cool wizard option of the magnificent open source Installer editor <a href="http://hmne.sourceforge.net/">HM NIS Edit</a> by Hector Mauricio Rodriguez Segura and just take your <code>setup.exe</code> and go. You can easily build really complex installers with custom controls with this tool as well - sky's the limit.</p>

<p><b>Launching the app</b><br />
Launching your java application is the next experience the user comes in contact with. If you choose to launch your application through some batch files or worse, let the user start the app through command line as mentioned above, you will most definitely burn in coder hell - and rightly so. There are quite a number of really useful java launchers out there that make launching a java app no less pain than a double click, though the application may actually have serious amounts of dependencies. My favourite one is the <a href="http://www.rolemaker.dk/nonRoleMaker/javalauncher/marner_java_launcher.htm">Marner Java Launcher</a> by Jacob Marner. It is basically a small executable program written in C, that launches your java VM with all your previously configured options. </p>

<p>Let's assume following example: You wrote a small app that uses a couple of java libraries and utilises the Eclipse SWT framework for the GUI. Now you want the java launcher to do all your bidding. Your first step should be to create a folder at the root of your project directory called <code>libraries</code> and copy <code>jface.jar</code>, <code>swt.jar</code> and whatever libraries you desire into it. Also, you should copy the native SWT dlls into a separate folder called <code>native</code>. In our case this would be swt-awt-win32-xxxx.dll and swt-win32-xxxx.dll from the eclipse directory <code>eclipse\plugins\org.eclipse.swt.win32_x.x.x\os\win32?</code>. Now we have gathered our source code, the dependent libraries and the native components in one directory. </p>

<p>Now we should create a jar file from our source code that contains a file in the root directory called <code>manifest.mf</code> file. The <code>manifest.mf</code> file contains information which Class should be launched as an entry point into our application (i.e. which class contains the <code>main()</code> method. Also it adds our dependent libraries from the <code>libraries</code> folder to our classpath. The <code>manifest.mf</code> file should look like this:</p>

<p><code>Manifest-Version: 1.0<br />
Main-Class: de.keyboardsamurais.ApplicationMain<br />
Class-Path: ./libraries/xmlrpc-1.2-b1.jar ./libraries/jface.jar ./libraries/log4j-1.2.8.jar ./lib/swt.jar</code></p>

<p>Eclipse Users can use the "Export" feature for the jar packaging. Now we are able to call our class from the command line via the call <code>java -jar application.jar</code>. Well...almost! Our application still lacks the native DLL components, so we need to tell the VM where they can be found via a -D flag. We can enter <code>java -Djava.library.path=./native/ -jar application.jar</code> and our app should run flawlessly.<br />
Now, that's the point where we configure the launcher.cfg file from our java launcher. For our example this config file would look like that:</p>

<p><code>.<br />
javaw.exe <br />
-Djava.library.path=./native/ -jar application.jar</code></p>

<p>If you do need an output window for log messages you can exchange <code>javaw.exe</code> for <code>java.exe</code>. You can now click on the Launcher.exe (which you should have copied into your project directory by now) and your application will run like a charm.</p>

<p>You can now wrap it all up into a nice installer and everybody will have a pleasant experience with your software deployment. You might want to change the icon of your launcher.exe to something more fitting. I recommend doing this with <a href="http://www.users.on.net/johnson/resourcehacker/">Resource Hacker</a> by Angus Johnson.</p>

<p><b>Last words</b><br />
Be aware that there are more than a few other options to do all of the above mentioned steps. One of the most promising install systems is <a href="http://java.sun.com/products/javawebstart/">Java WebStart</a> and there are a couple of multi platform installers that promise "Write once, run anywhere". However I am quite happy with the above solution.</p>]]></description>
			<content:encoded><![CDATA[<p>When building a client side Java application, with whatever GUI Framework happens to be your favourite one (AWT, Swing, SWT - just to name the obvious triplet), at some point you really have got to ask yourself what would be the best way to distribute your app, without causing the end-user too much pain.</p>
<p>I think that most people would agree that customer acceptance depends to a large extent on the first impression of the user with the particular product. The first contact with your software however, typically is the installation procedure. With java software and the advent of so called "Platform independent" solutions various attempts to address installation facilities have been tried, but just too often, java coders tend to neglect this duty shamefully. Pretty often you find yourself with some classes and jar files you need to copy all over your system, add extensions to your classpath and finally launch the app from the command line via :<code>java classname</code> just to watch it fail a dozen times before you discover that you forgot to add the <code>-Djava.library.path</code> property to the command line (as stated in the readme.txt at line 1846).</p>
<p><strong>The Installer</strong><br />
Windows users can be very choosey about standardized installation procedures, thus I would recommend using a native Windows Installer like the <a href="http://nsis.sourceforge.net/home/">Nullsoft Install System</a> to create an installer (i.e. a <code>Setup.exe</code>) for your application that can be installed and uninstalled properly in a standard, Windows way<sup>tm</sup>. NSIS offers a pretty cool, powerful macro language for installers that you fortunately don't really have to learn to create your typical basic installer. For the average installer it is sufficient to use the really cool wizard option of the magnificent open source Installer editor <a href="http://hmne.sourceforge.net/">HM NIS Edit</a> by Hector Mauricio Rodriguez Segura and just take your <code>setup.exe</code> and go. You can easily build really complex installers with custom controls with this tool as well - sky's the limit.</p>
<p><strong>Launching the app</strong><br />
Launching your java application is the next experience the user comes in contact with. If you choose to launch your application through some batch files or worse, let the user start the app through command line as mentioned above, you will most definitely burn in coder hell - and rightly so. There are quite a number of really useful java launchers out there that make launching a java app no less pain than a double click, though the application may actually have serious amounts of dependencies. My favourite one is the <a href="http://www.rolemaker.dk/nonRoleMaker/javalauncher/marner_java_launcher.htm">Marner Java Launcher</a> by Jacob Marner. It is basically a small executable program written in C, that launches your java VM with all your previously configured options.</p>
<p>Let's assume following example: You wrote a small app that uses a couple of java libraries and utilises the Eclipse SWT framework for the GUI. Now you want the java launcher to do all your bidding. Your first step should be to create a folder at the root of your project directory called <code>libraries</code> and copy <code>jface.jar</code>, <code>swt.jar</code> and whatever libraries you desire into it. Also, you should copy the native SWT dlls into a separate folder called <code>native</code>. In our case this would be swt-awt-win32-xxxx.dll and swt-win32-xxxx.dll from the eclipse directory <code>eclipse\plugins\org.eclipse.swt.win32_x.x.x\os\win32?</code>. Now we have gathered our source code, the dependent libraries and the native components in one directory.</p>
<p>Now we should create a jar file from our source code that contains a file in the root directory called <code>manifest.mf</code> file. The <code>manifest.mf</code> file contains information which Class should be launched as an entry point into our application (i.e. which class contains the <code>main()</code> method. Also it adds our dependent libraries from the <code>libraries</code> folder to our classpath. The <code>manifest.mf</code> file should look like this:</p>
<p><code>Manifest-Version: 1.0<br />
Main-Class: de.keyboardsamurais.ApplicationMain<br />
Class-Path: ./libraries/xmlrpc-1.2-b1.jar ./libraries/jface.jar ./libraries/log4j-1.2.8.jar ./lib/swt.jar</code></p>
<p>Eclipse Users can use the "Export" feature for the jar packaging. Now we are able to call our class from the command line via the call <code>java -jar application.jar</code>. Well...almost! Our application still lacks the native DLL components, so we need to tell the VM where they can be found via a -D flag. We can enter <code>java -Djava.library.path=./native/ -jar application.jar</code> and our app should run flawlessly.<br />
Now, that's the point where we configure the launcher.cfg file from our java launcher. For our example this config file would look like that:</p>
<p><code>.<br />
javaw.exe<br />
-Djava.library.path=./native/ -jar application.jar</code></p>
<p>If you do need an output window for log messages you can exchange <code>javaw.exe</code> for <code>java.exe</code>. You can now click on the Launcher.exe (which you should have copied into your project directory by now) and your application will run like a charm.</p>
<p>You can now wrap it all up into a nice installer and everybody will have a pleasant experience with your software deployment. You might want to change the icon of your launcher.exe to something more fitting. I recommend doing this with <a href="http://www.users.on.net/johnson/resourcehacker/">Resource Hacker</a> by Angus Johnson.</p>
<p><strong>Last words</strong><br />
Be aware that there are more than a few other options to do all of the above mentioned steps. One of the most promising install systems is <a href="http://java.sun.com/products/javawebstart/">Java WebStart</a> and there are a couple of multi platform installers that promise "Write once, run anywhere". However I am quite happy with the above solution.</p>
 <p><a href="http://keyboardsamurais.de/?flattrss_redirect&amp;id=63&amp;md5=f5b8917016438e2bb6b1c5fea813f1be" title="Flattr" target="_blank"><img src="http://keyboardsamurais.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://keyboardsamurais.de/2004/05/16/tutorial_deployment_of_client_side_java_or_eclipseswt_applications_on_windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tomcat Tutorial: HelloWorld for Complete Fools [English]</title>
		<link>http://keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/</link>
		<comments>http://keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>Toni</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p><i>The following tutorial was translated into English from the German original on this site, which is also available <a href="http://www.keyboardsamurais.de/mt/archives/000050.html">here</a>. Please excuse me for my poor english skills, I am not a native speaker.</i></p>
<p>I know quite a number of java developers who, despite their good knowledge of the java platform,
somehow failed to successfully deploy a new Servlet to a Apache Tomcat installation. I stress, that 
they did not fail because of their inferior skills, but because of the fact, that there is no comprehensive 
resource out there that explains the Tomcat deployment procedure:
<ul>
<li>in a nutshell</li>
<li>with pictures</li>
<li>without going into details that aren't of direct interest</li>
</ul>
So, without much further ado, I will try to explain how to install tomcat, create a deployment structure using Eclipse and writing a simple HelloWorld Servlet.
</p>]]></description>
			<content:encoded><![CDATA[<p><em>The following tutorial was translated into English from the German original on this site, which is also available <a href="http://www.keyboardsamurais.de/mt/archives/000050.html">here</a>. Please excuse me for my poor english skills, I am not a native speaker.</em></p>
<p><em><strong>Update 26.02.2007</strong>: Note, that this Article, though technically still relevant and valid, is not up to date with the progress of the eclipse platform. I created a screencast to reflect the changes that took place and to show you development with the Eclipse WTP. <a href="http://keyboardsamurais.de/2007/02/26/eclipse-wtp-and-tomcat-tutorial/">Click here for the article</a>.</em></p>
<p>I know quite a number of java developers who, despite their good knowledge of the java platform, somehow failed to successfully deploy a new Servlet to a Apache Tomcat installation. I stress, that they did not fail because of their inferior skills, but because of the fact, that there is no comprehensive<br />
resource out there that explains the Tomcat deployment procedure:</p>
<ul>
<li>in a nutshell</li>
<li>with pictures</li>
<li>without going into details that aren't of direct interest</li>
</ul>
<p>So, without much further ado, I will try to explain how to install tomcat, create a deployment structure using Eclipse and writing a simple HelloWorld Servlet.</p>
<p>In theory, deploying a Servlet is a really straightforward task - that is, if you know somebody who is willing to introduce you into the deployment mysticisms of the Apache Tomcat development. Unfortunately, I knew nobody who was really adroit with that. So I spent a really long time running into every single ambush Tomcat has to offer for blue eyed newbies. Hence I can rightly say, that Tomcat's configuration is a pain in the rear if you don't have an expert person who guides you through your very first steps. Even if you know your <a href="http://www.google.de">Google</a> search words cold, you won't find a single document that makes your task seem trivial.</p>
<p>So I figured, it would be best for newbies and the like, if you could just follow an example with pictures in it. In the following tutorial, I will try to explain the deployment procedure from the very beginning in step-by-step fashion to build a standard "Hello World" Servlet. To accomplish this, I will use the Eclipse IDE and Eclipse specific plugins, but I hope that one can understand the general proceeding that is necessary for other IDEs as well. I will assume that you are familiar with the installation of eclipse and eclipse plugins.</p>
<p>The following software will be neccessary to follow the tutorial:</p>
<ul>
<li><a href="http://ftp.leo.org/pub/comp/general/infosys/www/daemons/apache/dist/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.exe">Tomcat Servlet Container</li>
<li><a href="http://eclipse.org/downloads/index.php">Eclipse 3.X</a></li>
<li><a href="http://www.sysdeo.com/eclipse/tomcatPlugin.html">Sysdeo Eclipse Tomcat Launcher plugin</a></li>
</ul>
<p><strong>The Server</strong></p>
<p>Especially for Windows users it's pretty easy to install Tomcat, because there it has a straightforward installer script that rids you of most of the configuration work. Everything you have to do is set the Administrator password (and remember it!) and the installation directory (and remember it!).</p>
<p><strong>The Plugin</strong></p>
<p>The Sysdeo Tomcat Plugin is our best friend. After you have installed it, you will notice these buttons and menues in your IDE.</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_1.gif" /></center> The left button starts Tomcat, the middle button stops it, the right button restarts Tomcat. Right now, they won't work if you press them. To enable them, you first need to configure a few things. Go to the menu "Window-&gt; Preferences" there, you will see this dialogue box.</p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_2_max.gif"><img src="http://keyboardsamurais.de/pix/tomcat_tut_2_min.gif" width="180" height="196" border="0">Enlarge</a></p>
<p></center>Now you need to go to the menu item "Tomcat" and select your Tomcat version. At the time of writing that would be the 4.1  5.x version. Now we adjust the field "Tomcat Home" to point to the install directory that we selected before at install time. The Sysdeo plugin now knows where to look for the <code>server.xml</code> file and automatically assumes the standard path to look for the file. Eclipse is now able to manage this configuration file, i.e. add a new <code>&amp;lt;context&amp;gt;</code> for a new application.</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_3.gif" /></center><br />
The Tomcat servlet container, features multiple user roles, such as the "Administrator" that we have already added to the user configuration upon installation. All users and passwords are found (in plain text, so take care to handle this safely) in the <code>conf/tomcat-users.xml</code> file. We now need to add another user called "Manager" that was not added to the file at installation time. Therefor we scroll down the menu point "Tomcat" and click the item "Tomcat Manager App". Now we can add a username and a password for the manager. Subsequently we click on "Add user to tomcat-users.xml" and leave the configuration menu.</p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_4_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_4_min.gif" width="300" height="282" border="0"></a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_4_max.gif" target="_ksnew">Enlarge</a><br />
</center> Now we are ready to test start our Tomcat server. Click on the start button in the Tomcat menu and watch the console output. If Tomcat boots up without any stacktraces open your browser, and try to open the following address <code><a href="http://localhost:8080/">http://localhost:8080/</a></code> . If you see an image<br />
that is similar, to the one below everything is working okay. If it doesn't you might want to <a href="http://www.google.com">Google</a> on what might have caused the stacktrace.<br />
<center><img src="http://keyboardsamurais.de/pix/tomcat_tut_5.jpg" /></center></p>
<p><strong>Hello World</strong></p>
<p>For now, we stop out Tomcat server and take a look at our very own, first servlet. First, we need to open a new project in the navigator window.</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_6.gif" /></center><br />
In the project window we select "Tomcat Project"...</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_7.gif" /></center></p>
<p>...click on the Next button and call our new project "Hello World"</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_8.gif" /></center><br />
After a click on the next Button we now can adjust under which URI (Uniform Resource Identifier) we want our new application to respond to our requests. To illustrate what part of the URL this is, just take a look at the fat part in the following address: <code>http://localhost:8080<strong>/HelloWorld</strong>/hello</code>.<br />
The default adjustments on the other controls should be fine by now, so we don't bother to adjust them. They should look similar to following image.</p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_9_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_9_min.gif" width="300" height="93" border="0"</a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_9_max.gif" target="_ksnew">Enlarge</a></center><br />
If we now "Finish" the Wizard, we can see, that Eclipse has created a whole bunch of new directories. It should look similar to this:</p>
<p><center><img src="http://keyboardsamurais.de/pix/tomcat_tut_10.gif" /></center><br />
Now we can create a new class named <code>HelloServlet</code> in the directory <code>WEB-INF/src.</code> Now we can copy and paste following code into this class.</p>
<pre>
<strong>import</strong> java.io.*;

<strong>import</strong> javax.servlet.http.*;
<strong>import</strong> javax.servlet.*;

<strong>public</strong> class <strong>HelloServlet</strong> extends HttpServlet {
  <strong>public</strong> void <strong>doGet</strong> (HttpServletRequest <strong>req</strong>,
                                         HttpServletResponse <strong>res</strong>)
        throws ServletException, IOException
  {
        PrintWriter out = res.getWriter();
        out.println("Hello, Brave new World!");
        out.close();
  }
}</pre>
<p>Our View should now look like this:</p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_11_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_11_min.gif" /></a><br />
</a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_11_max.gif">Enlarge</a><br />
</center>Unfortunately we are not yet finished. We still need to create the <code>web.xml</code> descriptor, which contains certain elements of configuration specific to our application and the server behaviour. So we create the file <code>web.xml</code> in the directory <code>WEB-INF</code> (<strong>Note: not in the directory <code>WEB-INF/src</code> !!!</strong>). For our simple application, the following parameters should be fine.</p>
<pre>
&lt;!DOCTYPE web-app PUBLIC
  '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
  'http://java.sun.com/dtd/web-app_2_3.dtd'&gt;
&lt;web-app&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
    &lt;servlet-class&gt;HelloServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
&lt;/web-app&gt;</pre>
<p>What follows now is a little explanation of what we just copied and pasted into <code>web.xml</code> . The Doctype is an xml specific item that tells the xml parser where to look<br />
for the dtd consistency rules for our xml document. The dtd ensures that no wrong parameter combinations are entered. The main tag <code>&amp;lt;web-app&amp;gt;</code> contains all preferences for our servlet. The <code>&amp;lt;servlet&amp;gt;</code> tag basically contains the name (<code>&amp;lt;servlet-name&amp;gt;)</code> that will be used throughout the xml document to reference our servlet and its linked class (<code>&amp;lt;servlet-class&amp;gt;</code>) . The tag <code>&amp;lt;servlet-mapping&amp;gt;</code> is responsible for telling the server, to what document name in the URL our application should respond to. Note, that the correct order of these tags has to be retained to form a valid <code>web.xml</code> descriptor. If we followed all steps correctly, we should now be able to fire up Tomcat again. Our workspace should now look like that:</p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_12_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_12_min.gif" width="300" height="221" border="0">Enlarge</a></center><br />
So, if we now enter the right combination of URI and resource name into the address bar of our browser (in our case this would actually be <code><a href="http://localhost:8080/HelloWorld/hello" target="_ksnew">http://localhost:8080/HelloWorld/hello</a></code>) we should be able to see the output from our very first servlet. Congratulations, now you are in the game <img src='http://keyboardsamurais.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><center><a href="http://keyboardsamurais.de/pix/tomcat_tut_13_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_13_min.gif" width="300" height="147" border="0">Enlarge</a></center><br />
Oh, yeah - if you want to enable your Tomcat engine to serve JSPs too, you just have to add the following lines to the web.xml file and put the jsp files in the top level directory of your eclipse project.</p>
<pre>    &lt;servlet&gt;
        &lt;servlet-name&gt;jspAssign&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.apache.jasper.servlet.JspServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;logVerbosityLevel&lt;/param-name&gt;
            &lt;param-value&gt;WARNING&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;fork&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;3&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;jspAssign&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/*.jsp&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;</pre>
<p>For further reading, I recommend following Sites:</p>
<p><a href="http://jakarta.apache.org/tomcat/tomcat-4.1-doc/index.html" target="_ksnew">Tomcat 4.1 Documentation</a><br />
<a href="http://www.apl.jhu.edu/%7Ehall/java/Servlet-Tutorial/" target="_ksnew">Advanced JSP and Servlet Tutorial</a></p>
 <p><a href="http://keyboardsamurais.de/?flattrss_redirect&amp;id=41&amp;md5=f4f2d88520f5816e6a11ef855b155b60" title="Flattr" target="_blank"><img src="http://keyboardsamurais.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
		<item>
		<title>Tomcat Tutorial: HelloWorld for Complete Fools ;-)</title>
		<link>http://keyboardsamurais.de/2003/11/29/tomcat_tutorial_helloworld_for_complete_fools_/</link>
		<comments>http://keyboardsamurais.de/2003/11/29/tomcat_tutorial_helloworld_for_complete_fools_/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>Toni</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>
<a href="http://www.keyboardsamurais.de/mt/archives/000053.html" target="ksnew"><img border="0" hspace="20" src="http://www.keyboardsamurais.de/pix/bp29.gif "align="left"></a>
<i>This Tutorial is also available in English <a href="http://www.keyboardsamurais.de/mt/archives/000053.html" target="ksnew">here</a></i></p>
<p>Ich kenne einige erfahrene Java Entwickler, die bereits daran gescheitert sind 
  ein eigenst&#228;ndiges Servlet Projekt auf Apache Tomcat Basis einzurichten. 
  Entwickler, die komplexeste Neuronale Netze wie im Schlaf entwickeln und die 
  EJB Spezifikation r&#252;ckw&#228;rts beten k&#246;nnen, haben hier schon ihre 
  Probleme gehabt. Man kann also mit Recht sagen, da&#223; es nicht selbsterkl&#228;rend 
  ist ein Servlet auf dem Tomcat Container zur Mitarbeit zu &#252;berreden. <code>.WAR</code> 
  Archive deployen an sich kann jeder, aber ganz anders sieht das aus wenn ein 
  brandneues Projekt in einen eigenen <code>Context</code> gesetzt werden soll und die Verzeichnisstruktur 
  entsprechend der Spezifikation erstellt werden muss et cetera, et cetera, et 
  cetera. Als Neuling muss man sich also erst Recht nicht sch&#228;men, wenn man 
  Anfangsproblemchen mit Servlets hat.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.keyboardsamurais.de/mt/archives/000053.html" target="ksnew"><img src="http://www.keyboardsamurais.de/pix/bp29.gif" align="left" border="0" hspace="20" /></a><br />
<em>This Tutorial is also available in English <a href="http://www.keyboardsamurais.de/mt/archives/000053.html" target="ksnew">here</a></em></p>
<p><em><strong>Update 26.02.2007</strong>: Obwohl die Grundlagen dieses Artikels immer noch gelten und richtig sind, gibt es mittlerweile einige Entwicklungen an der Eclipse Platform die es sich lohnt anzuschauen. Insbesondere die Eclipse Web Tools Platform. Ich habe zu diesem Zweck einen Screencast erstellt der eine EinfÃ¼hrung in das Entwickeln mit WTP gibt. Ihr findet ihn <a href="http://keyboardsamurais.de/2007/02/26/eclipse-wtp-and-tomcat-tutorial/">in diesem Artikel</a>.</em></p>
<p>Ich kenne einige erfahrene Java Entwickler, die bereits daran gescheitert sind ein eigenstÃ¤ndiges Servlet Projekt auf Apache Tomcat Basis einzurichten. Entwickler, die komplexeste Neuronale Netze wie im Schlaf entwickeln und die EJB Spezifikation rÃ¼ckwÃ¤rts beten kÃ¶nnen, haben hier schon ihre Probleme gehabt. Man kann also mit Recht sagen, daÃŸ es nicht selbsterklÃ¤rend ist ein Servlet auf dem Tomcat Container zur Mitarbeit zu Ã¼berreden. <code>.WAR</code> Archive deployen an sich kann jeder, aber ganz anders sieht das aus wenn ein<br />
brandneues Projekt in einen eigenen <code>Context</code> gesetzt werden soll und die Verzeichnisstruktur entsprechend der Spezifikation erstellt werden muss et cetera, et cetera, et cetera. Als Neuling muss man sich also erst Recht nicht schÃ¤men, wenn man Anfangsproblemchen mit Servlets hat.</p>
<p>Um diese Anfangsschwierigkeit zu mildern habe ich dieses Tutorial geschrieben.</p>
<p>Dabei ist es eigentlich hÃ¶llisch einfach so ein Servlet zum laufen zu bringen - vorausgesetzt man kann bei jemandem Nachfragen, der bereits die hohe Kunst der Tomcat Administration beherrscht. Ich kannte niemanden, der das konnte und habe ewig lange Zeit damit verbracht jeden Fehler den ein AnfÃ¤nger begehen kann zu begehen. Daher weiÃŸ ich wovon Ich spreche wenn ich sage, die Konfiguration von Tomcat ist ohne UnterstÃ¼tzung einer kundigen Person, selbst unter Zuhilfenahme von <a href="http://www.google.de">Google</a> alles andere als trivial.</p>
<p>In diesem Tutorial werde ich versuchen so detailliert wie mÃ¶glich zu erklÃ¤ren wie man <em>step-by-step</em> vorgeht um ein simples â€œHello Worldâ€ Servlet unter Tomcat 4 zum laufen zu bekommen. FÃ¼r das Tutorial verwende ich Eclipse und Eclipse Spezifische Plugins. Ich hoffe dennoch, daÃŸ man sich aus den Darstellungen die generelle Vorgehensweise abschauen kann um das gleiche auch fÃ¼r andere Entwicklungsumgebungen zu bewerkstelligen. Es wird hierbei vorausgesetzt, daÃŸ die Installation von Eclipse und der Umgang<br />
mit Plugins gelÃ¤ufig sind.</p>
<p>Folgende Software wird also zunÃ¤chst benÃ¶tigt:</p>
<ul>
<li><a href="http://ftp.leo.org/pub/comp/general/infosys/www/daemons/apache/dist/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.exe">Tomcat Servlet Container</a></li>
<li><a href="http://eclipse.org/downloads/index.php">Eclipse 3.X</a></li>
<li><a href="http://www.sysdeo.com/eclipse/tomcatplugin">Sysdeo Eclipse<br />
Tomcat Launcher plugin</a></li>
</ul>
<p>Der Server</p>
<p>Tomcat zu installieren ist besonders fÃ¼r Windows Benutzer recht einfach, da ein guter Installer alle Konfigurationsarbeit abnimmt. Alles was man noch zu tun hat ist, sich das Admin Passwort und Verzeichnis zu merken in das Tomcat installiert wurde.</p>
<p><strong>Das Plugin</strong></p>
<p>Das Sysdeo Tomcat Plugin ist unser Freund und Helfer. Nachdem es installiert wurde erscheinen prompt folgende Buttons und MenÃ¼s in der Bedienleiste von Eclipse.</p>
<p><img src="http://keyboardsamurais.de/pix/tomcat_tut_1.gif" height="82" width="185" /></p>
<p>Die drei Kater bedeuten in der Reihenfolge von Links nach Rechts Start, Stop und Neu starten. Noch funktionieren sie nicht, denn wir mÃ¼ssen zunÃ¤chst noch einige Einstellungen vornehmen. Hierzu gehen wir in das MenÃ¼ â€œWindow-&gt; Preferencesâ€ dort Ã¶ffnet sich nun folgender Dialog<br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_2_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_2_min.gif" border="0" height="196" width="180" /></a></p>
<p><a href="http://keyboardsamurais.de/pix/tomcat_tut_2_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Im MenÃ¼punkt Tomcat tragen wir nun ein, welche Version von Tomcat wir benutzen. Zum heutigen Zeitpunkt ist das die 4.1er oder die 5er Version. In das Feld â€œTomcat<br />
Homeâ€ geben wir das Verzeichnis ein in das Tomcat installiert wurde. Der Pfad zur Konfigurationsdatei <code>server.xml</code> wird nach der Eingabe des<br />
â€œTomcat Homeâ€ automatisch ergÃ¤nzt. Eclipse wird fortan fÃ¼r uns diese Konfigurationsdatei verwalten, in der zum Beispiel der <code>&amp;lt;context&amp;gt;</code> einer Applikation gesetzt wird.<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_3.gif" height="163" width="300" /></p>
<p>Ein Tomcat Server besitzt verschiedene Benutzerrollen. Einen besonderen Benutzer, den â€œAdministratorâ€, haben wir bereits bei der Installation angelegt. Seine Benutzername und sein Passwort finden sich in der Datei <code>tomcat-users.xml</code>. Ein weiterer Benutzer ist der Benutzer â€œManagerâ€, er ist nach der normalen Installation noch nicht angelegt und muss manuell hinzugefÃ¼gt werden. Diese Arbeit nimmt uns Eclipse allerdings ab, wenn wir nun die UntermenÃ¼s von Punkt Tomcat aufklappen und dort den Punkt â€œTomcat Manager Appâ€ aufrufen. Hier kann nun ein Benutzername und ein Passwort fÃ¼r den Manager festgelegt werden. AnschlieÃŸend auf den Button â€œAdd user to tomcat-users.xmlâ€ clicken und dir Konfiguration verlassen.</p>
<p><a href="http://keyboardsamurais.de/pix/tomcat_tut_4_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_4_min.gif" border="0" height="282" width="300" /></a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_4_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Jetzt kÃ¶nnen wir zu Probehalber Tomcat starten. Hierzu clicken wir auf den oben genannten Knopf auf dem der Tomcat Kater abgebildet ist. Wenn Tomcat ohne jegliche Stacktraces hochfÃ¤hrt und wir uns jetzt mit dem Browser auf <code><a href="http://localhost:8080/">http://localhost:8080/</a></code> verbinden kÃ¶nnen und unten stehende Startseite sehen ist alles in Ordnung.<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_5.jpg" height="242" width="300" /></p>
<p><strong>Hello World</strong></p>
<p>Jetzt beenden wir Tomcat allerdings erstmal wieder. Und widmen uns unserem ersten Servlet. Hierzu erzeugen wir ein neues Projekt im Navigator Fenster<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_6.gif" height="156" width="268" /></p>
<p>Im Projektfenster wÃ¤hlen wir jetzt Tomcat Projekt ausâ€¦<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_7.gif" height="80" width="126" /></p>
<p>â€¦clicken auf â€œNextâ€ und benennen unser Projekt.â€HelloWorldâ€<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_8.gif" height="127" width="187" /></p>
<p>Nach einem click auf â€œNextâ€ kÃ¶nnen wir nun angeben unter welcher<br />
URI (Uniform Resource Identifier) wir unsere Anwendung im Browser kÃ¼nftig ansprechen wollen. Dies entspricht dem im Folgenden, dick gedruckten Teil in<br />
unserer Adresse: <code>http://localhost:8080<strong>/HelloWorld</strong>/hello</code> Wir belassen alles so wie es ist. DaÃŸ bedeutet wir lassen Eclipse die<br />
XML Dateien von Tomcat verwalten und legen fÃ¼r unsere Applikation fest, daÃŸ sie nicht in einem Unterverzeichnis sondern im Hauptverzeichnis abgerufen werden soll. Es sollte also so aussehen wie auf folgender Darstellung.</p>
<p><a href="http://keyboardsamurais.de/pix/tomcat_tut_9_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_9_min.gif" border="0" height="93" width="300" /></a></p>
<p><a href="http://keyboardsamurais.de/pix/tomcat_tut_9_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Wenn wir nun den Wizard mit â€œFinishâ€ beenden, so sehen wir das Eclipse uns gleich eine ganze Sammlung an Verzeichnissen angelegt hat. Es sollte wie<br />
folgt aussehen.<br />
<img src="http://keyboardsamurais.de/pix/tomcat_tut_10.gif" height="235" width="190" /></p>
<p>Im Verzeichnis <code>WEB-INF/src</code> legen wir nun eine neue Klasse an, die wir <code>HelloServlet</code> nennen. Der Code, fÃ¼r diese Klasse sieht folgendermaÃŸen aus.</p>
<pre>
<strong>import</strong> java.io.*;

<strong>import</strong> javax.servlet.http.*;
<strong>import</strong> javax.servlet.*;

<strong>public</strong> class <strong>HelloServlet</strong> extends HttpServlet {
  <strong>public</strong> void <strong>doGet</strong> (HttpServletRequest <strong>req</strong>,
                                         HttpServletResponse <strong>res</strong>)
        throws ServletException, IOException
  {
        PrintWriter out = res.getWriter();
        out.println(â€Hello, Brave new World!â€);
        out.close();
  }
}
</pre>
<p>Unsere Ansicht sieht also nun so aus.<br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_11_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_11_min.gif" border="0" height="281" width="300" /></a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_11_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Leider ist es damit allerdings noch nicht getan. ZunÃ¤chst mÃ¼ssen wir noch den <code>web.xml</code> Deskriptor anlegen der u.a. angibt unter welchem Namen wir das Servlet Ã¼ber den Browser ansprechen kÃ¶nnen. Die Datei<br />
<code>web.xml</code> muss im Verzeichnis <code>WEB-INF</code> angelegt werden ( <strong>NICHT IM VERZEICHNIS <code>WEB-INF/src</code> !!!</strong>). FÃ¼r<br />
unsere Anwendung sollte sie folgende EintrÃ¤ge enthalten.</p>
<pre>
&lt;!DOCTYPE web-app PUBLIC
  '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
  'http://java.sun.com/dtd/web-app_2_3.dtd'&gt;
&lt;web-app&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
    &lt;servlet-class&gt;HelloServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre>
<p>Hierzu ist zunÃ¤chst eine kleine ErklÃ¤rung notwendig. Der Doctype tag gibt an wo sich die ÃœberprÃ¼fungsregeln zu unserem xml Dokument finden. So kann man sicher gehen, daÃŸ sich keine falschen Parameterkonstellationen einschleichen. Der Haupt Tag &lt;web-app&gt; enthÃ¤lt alle sonstigen Einstellungen. Im Tag Servlet wird vor allem der Name (&lt;servlet-name&gt;) mit dem das Servlet innerhalb des XML Dokuments fortan benannt wird, mit der Klasse (&lt;servlet-class&gt;) verknÃ¼pft. Im Tag &lt;servlet-mapping&gt; geht es darum dem Server mitzuteilen welchen Dokumentnamen unser Servlet bekommen soll, wenn man es schlieÃŸlich Ã¼ber die Browserzeile aufruft. Wichtig ist hierbei, daÃŸ man die Reihenfolge in der die Tags geschrieben sind beachtet. Tomcat achtet penibel genau, daÃŸ die Reihenfolge eingehalten wird. So muÃŸ <code>&amp;lt;servlet&amp;gt;</code> immer vor dem <code>&amp;lt;servlet-mapping&amp;gt;</code> definiert worden sein, und <code>&amp;lt;servlet-name&amp;gt;</code> muss in <code>&amp;lt;servlet-mapping&amp;gt;</code> vor <code>&amp;lt;url-pattern&amp;gt;</code> stehen. Wenn wir jetzt alle Schritte richtig augefÃ¼hrt haben, kÃ¶nnen wir endlich Tomcat starten. Unsere Umgebung sollte nun folgendermaÃŸen aussehen.<br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_12_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_12_min.gif" border="0" height="221" width="300" /></a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_12_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Wenn wir jetzt die Kombination aus der URI und dem &lt;servlet-mapping&gt; in der Addresszeile des Browsers eingeben, also in unserem Fall die Adresse<code><a href="http://localhost:8080/HelloWorld/hello" target="_ksnew">http://localhost:8080/HelloWorld/hello</a></code> sollten wir nun endlich die Ausgabe unseres Servlets sehen kÃ¶nnen. Hurrah! <img src='http://keyboardsamurais.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://keyboardsamurais.de/pix/tomcat_tut_13_max.gif" target="_ksnew"><img src="http://keyboardsamurais.de/pix/tomcat_tut_13_min.gif" border="0" height="147" width="300" /></a><br />
<a href="http://keyboardsamurais.de/pix/tomcat_tut_13_max.gif" target="_ksnew">VergrÃ¶ssern</a></p>
<p>Wer unter Tomcat auch JSPs verwenden will, der kann einfach folgende Zeilen zur web.xml datei hinzufÃ¼gen und anschlieÃŸend die JSP Dateien im Hauptverzeichnis des eclipse projektes ablegen.</p>
<pre>
    &lt;servlet&gt;
        &lt;servlet-name&gt;jspAssign&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.apache.jasper.servlet.JspServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;logVerbosityLevel&lt;/param-name&gt;
            &lt;param-value&gt;WARNING&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;fork&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;3&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;jspAssign&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/*.jsp&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
</pre>
<p>Die weitere Entwicklung von Servlets unter Eclipse ist Ã¼brigens sehr angenehm. Die meisten einfachen CodeÃ¤nderungen, werden beim speichern in den Servlet Container Ã¼bernommen, so daÃŸ man nicht jedes Mal den Server neu starten oder ein neues Deployment anfangen muss. Viel SpaÃŸ mit der weiteren Entwicklung.</p>
 <p><a href="http://keyboardsamurais.de/?flattrss_redirect&amp;id=33&amp;md5=749fe339ea4bbb931c5f4472d9b262f7" title="Flattr" target="_blank"><img src="http://keyboardsamurais.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://keyboardsamurais.de/2003/11/29/tomcat_tutorial_helloworld_for_complete_fools_/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
	</channel>
</rss>

