Examples: Install Examples
All examples presented in this course (that can be downloaded from the example page) are deployed usingant
. In order to work,
you need to configure ant according to your environment (where is
tomcat), or to integrate the example in your favorite IDE (Eclipse,
IntelliJ or NetBeans).
Install Apache-Tomcat
- Security measure: Configure the firewall of your machine such as to prevent any access from outside to your port 8080. Since the configuration I propose here is not secure, this will prevent someone to attack your computer. (I would recomand that you close all ports if you don't know the reason why they must be open.)
- Download Apache Tomcat from the internet: tomcat.apache.org (Tomcat 8.0 is the current version).
- Attention! For Windows users. You should not install Tomcat in the Program Files directory, because only admin has the right to write in this directory and you should be able to write inside the webapps directory of tomcat.
- In the conf directory, configure the tomcat-user.xml file. You have to add a new role manager-gui and and one new user having this role.
<role rolename="manager-gui"/> <user username="bie1" password="tomcat" roles="manager-gui" />
- Start your server:
In the bin directory start the application ./startup.sh or startup.bat for Windows. You can test your server using the following URI:
http://localhost:8080 -
Test your installation:
- Clic on the Tomcat Manager link. Logg-in using username and password defined in the file tomcat-user.xml
- In the tomcat manager window, you can manage all your applications. You will start, stop, and restart your programs.
- Clic on the link Examples and then servlets.
- Visit those examples rapidly (we will go back to the servlet syntax later).
Integrate in your own machine for editing with an editor
- You download the zip file containing the example seen in course (for instance servletHelloworld.zip).
-
Uncompress this file:
> unzip servletHelloworld.zip
-
Copy this directory in the
development
directory. - Import the file build.properties in the same directory. Adapt the values to your own environment (change the directory for tomcat - libs and webapps).
-
Edit the file
build.xml
, such that the line<property file="../../build.properties"/>
points toward the new property file you just edited. -
If you want you can change the value of the following variable, it is the name of the application (in the URL)
<property name="app.name" value="servlet-exemple-bie1"/>
- Once installed type
> ant deploy
to transfer your example to your tomcat server.
In your own machine (for editing with eclipse)
- Unzip the corresponding zip-file (for instance servletHelloworld.zip)
- Copy the file build.properties in the same directory.
- Start Eclipse
- Create a new Java Project (do not start with a JSF or JSP
project). Chose
New / Project ... / Java Project
- Close Eclipse
- Copy all the files from my example into the new directory in the workspace
- Restart Eclipse
- Change the classpath of the project: include alls Jars in the lib directory (none in the servlet project, more will come), and include all the jars in Tomcat.
- Edit the file
build.xml
. Change the reference tobuild.properties
to point to the right file:
Replace<property file="../../build.properties"/>
with<property file="build.properties"/>
- Edit the
build.properties
file, to reflect where you installed Tomcat. You must include all the jars in Tomcatlib
directory. - You should deploy using the ant task
deploy
(but sometimes a clean is also needed to remove old files).
In a virtual machine
All examples are integrated inside one virtual machine. The professor has some USB sticks containing the OVA-file of a virtual machine. You need to copy this file.Projects for editing with a normal editor (vi, emacs, gedit, ...)
- Projects can be found in the directory
~/examples
- Each project can be deployed using
ant deploy
- All projects are already installed inside Eclipse
- Deploy using ant task
deploy
(right click on the build.xml file).
- Both IDE's are installed, but IntelliJ is installed in the free version.
- Import the Eclipse project directly inside the IDE.
Related Pages
Contact
Prof. Dr. Emmanuel Benoist
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Social Networks
Follow
me
on
Linkedin, Scholar
& Research gate