ECLIPSE and TOMCAT (web applications)

Apache Tomcat & Eclipse Platform make a great Web development platform. Tutorials about this development environment are available on the following websites:

I use the Tomcat version 5.5.23 as localhost because this version is available on my hosted website provided by my ISP Visual Online. My Eclipse version is Galileo (3.5.2). The Java SDK is 1.6.

Web applications are deployed on the Tomcat server with a WAR file (which stands for “web application archive” ) A WAR file is a ZIP file used to distribute a collection of JavaServer Pages, servlets, Java classes, XML files, tag libraries and static Web pages that together constitute the Web application.

There are special files and directories within a WAR file.

  • The /WEB-INF/classes directory contains the .class files (servlets, …)
  • The /WEB-INF/lib directory contains the .jar files with the Java librairies
  • The /WEB-INF directory contains a file named web.xml which defines the structure of the web application

The main elements of the web.xml file are shown below :

<?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”>

<display-name>MyExampleWebProject</display-name>
<description>Describe What the application is doing and add comments</description>

<servlet>

<servlet-name>MyServlet</servlet-name>
<servlet-class>saraproft.com.servlet.FirstApp</servlet-class>
<description>Une application très simple</description>

<init-param>
<param-name>size</param-name>
<param-value>123</param-value>
</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>echo</url-pattern>
</servlet-mapping>

</web-app>

The elements of a web.xml file are :

  • the name of the application : <display name>
  • the name, class and parameters of the servlet : <servlet>
  • the mapping of the servlet : <servlet-mapping>
  • context parameters : <context-param>
  • session parameters : <session-config>
  • list of index files : <welcome-file-list>
  • MIME mapping : <mime-mapping>
  • other parameters referring to security, errors, filters, …

The other files (html, jsp, iamges, …) are stored in the root or in folders located in the root of the WAR file. They can’t be included in the WEB-INF directory.

NetBeans : another IDE

“What IDE is the best : Eclipse or NetBeans ?” is an often discussed topic among developpers.

NetBeans is a free, open-source Integrated Development Environment for software developers with all the tools you need to create professional desktop, enterprise, web, and mobile applications with the Java language, C/C++, and even dynamic languages such as PHP, JavaScript, Groovy, and Ruby. The actual version of NetBeans is 6.5.

Processing and Eclipse

Last update : January 21, 2014

Processing is an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production.

Processing is an open project initiated by Ben Fry and Casey Reas. It evolved from ideas explored in the Aesthetics and Computation Group at the MIT Media Lab. Development of Processing began formally in the Spring of 2001, the first alpha release 0001 was used in August 2001, the version 1.0 was released on 24th November 2008, a few days after the last beta version (release 157). Version 2 was released on September 5, 2013. The current version is 2.1 launched on October 27, 2013.

Processing programs can be easely exported to run on the web as Jas applications to run on Windows, Linux, Mac OS X or Android, as Java applets / Java projects or as Javascript web projects. Processing scripts are called sketches. Sometimes it might be useful to combine a Processing sketch with a general Java project, which is best done in Eclipse.

A tutorial how to use Processing in Eclipse is available on the Processing website. The following code has been saved as file MyEclipseSketch.java and runs succesfully as applet in Eclipse.

import processing.core.*;
public class MyFirstSketch extends PApplet{

public void setup() {
size (400,400);
background(0);
}
public void draw() {
stroke (255);
if (mousePressed) {
line (mouseX,mouseY,pmouseX,pmouseY);
}
}
}

To embed the applet in a webpage, the generated MyEclipseSketch.class file was added to the Processing archive core.jar and I renamed the archive file to eclipse_sketch.jar. The html code to display the applet is very easy :

<html>
<header>
</header>
<body>
<applet code=”MyEclipseSketch.class” archive=”eclipse_sketch.jar”/>
</body>
</html>

ECLIPSE – an open development platform

Last update : June 29, 2015

Eclipse is an open source community whose projects are focused on building an open development platform comprised of extensible frameworks, tools and runtimes for building, deploying and managing software across the lifecycle. A detailed overview about the Eclipse software is available at Wikipedia.

I started a year ago to use the EUROPA version (platform 3.3) of Eclipse to develop JAVA applications for the web. I changed  later to the  release GANYMEDE (plaform 3.4.) published in june 25th, 2008. I used the IDE for Java EE Developers (163 MB) with tools for Java developers creating JEE and Web applications.

A tutorial how to create servlets with Eclipse has been published on the Java Tips website. A french tutorial about servlets and jsp pages with Eclipse and Tomcat is available at the website of Serge Tahé (Maître de conférences en Informatique à l’université d’Angers). Another useful tutorial about Struts (méthode de développement gérée par l’Apache Software Foundation qui a pour but de fournir un cadre standard de développement d’applications web en Java respectant l’architecture dite MVC : Modèle – Vue – Contrôleur ) has been edited by the same author.

Other interesting tutorials are listed below :

To integrate my existing Java projects in Eclipse, I created a new Java Project in the Eclipse Workspace, copied the folder with the source files in this new project folder and executed the file – refresh menu.

The Eclipse platform is also used for Android developments, a preconfigured ECLIPSE version is included in the Google Android SDK.

In the context of the OFUR project, I installed in late June 2015 the new Eclipse Mars version (4.5) with the Javascript Development Tools (from the Web, XML, JavaEE and OSGi section), the Eclipse Web Developer Tools and the jshint Tools.

I added my signature files ida_dsa and ida_rsa to the SSH2 settings in the Eclipse – Window – Preferences – General -Network Connections – SSH2 menu. I accepted the default location for the workspace (users/mbarnig/workspace) and for the local GIT repository (users/mbarnig/git) in the Eclipse – Window – Preferences – Team – Git menu.

To checkout the original code for the DICOM Web Viewer (DWV),  I entered the HTTPS clone URL of the DWV Github front page to the Git Repository in the Eclipse – Window – Show View – Others – Git menu, clicked the Clone a Git Repository action and selected the master branch to start the download of the source code.

The DWV tree was loaded into the local DWV repository. In the root source folder the file eclipse.epf (Eclipse Process Framework Project) produces a customizable software process enginering framework. I imported the .epf file with the menu File – Import – General – Preferences.