8.4 KiB
Dude! Where's my Eclipse!?
- Dude! Where's my Eclipse
Dude! Where's my Eclipse
Pre-requisites
You will need a linux server with the following installed:
- tomcat
- This demo was prepare with tomcat-8.
- tomcat manager
- Used for deploying the your built application
- A web browser
- for accessing the tomcat manager
- git
- to access the project
- a text editor
- to fix any bugs you find (Not
eclipse
, because that's the whole point.) - java 8 JDK
- to build code
If you develop on one machine and deploy to the other, then tomcat and tomcat manager are to be on the system you're deploying to, and the rest where you're developing.
If your development environment is not on the same server as the
tomcat instance, you'll need a copy of the file
tomcat8-servlet-api.jar
on the same system as your java code.
Setting up
- All commands assume a Linux environment.
${HOME}
refers to the home directory of the user, and${DEV_HOME}
refers to where the git repository has been cloned to. -
Get the code
git clone https://gitlab.com/eibhear/javaBootcampNoEclipse.git
The repository is now in
${DEV_HOME}
. Change into it:export DEV_HOME=$(pwd)/javaBootcampNoEclipse cd ${DEV_HOME}
-
Make sure you're at the starting point:
git checkout lesson-1
Lesson 1 – compile the code.
Starting point
A clean git working area
Goal
Java files compiled into class files
Steps
-
Confirm you can access the java compiler:
javac -version
If this doesn't result in a message like
javac 1.8.0_141
, you'll need to find wherejavac
installed and place it on your${PATH}
. -
Change to where the code is:
cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse
-
Compile the files:
javac *.java
- Check the errors. If you see the message
error: package javax.servlet does not exist
, then look at yourCLASSPATH
setting, as dependend libraries are missing. -
Fix your
CLASSPATH
and compile the java files:export CLASSPATH=/usr/share/java/tomcat8-servlet-api.jar:${CLASSPATH} javac *.java
-
If the successful, you will have the following additional files:
${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
If this is the case, move on to lesson 2:
git checkout lesson-2
Lesson 2 – build the jar file
Starting point
A clean git working area with two additional class files
Goal
Class files archived into a jar file
Steps
- Decide whether you want to include the source (
*.java
) files in the jar file - Determine other files to be included in the jar file (e.g. config files, property files, etc.)
-
Change to the top-level of the package in the source:
cd ${DEV_HOME}/source/java
Create the
lib/
directory to take the jar file:mkdir -pv ../lib
If you're not including the source files in the jar:
jar cvf ../lib/javaBootcampNoEclipse.jar org/gibiris/javaBootcampNoEclipse/*.class
If you are including the source files in the jar:
jar cvf ../lib/javaBootcampNoEclipse.jar org/gibiris/javaBootcampNoEclipse/*
-
If the successful, you will now have a new file:
${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar
If this is the case, move on to lesson 3:
git checkout lesson-3
Lesson 3 – build the war file
Starting point
A clean git working area with two additional class files and one additional jar file.
Goal
A deployable war file
Steps
-
Review the following:
- http://tomcat.apache.org/tomcat-8.0-doc/appdev/deployment.html
to understand the structure of the
war
file and theweb.xml
file ${DEV_HOME}/source/res/web.xml
to understand how this application is to be used.
- http://tomcat.apache.org/tomcat-8.0-doc/appdev/deployment.html
to understand the structure of the
-
Create an empty directory in
${DEV_HOME}
calledwebapp
, then its directory structure and then change into it:mkdir -vp ${DEV_HOME}/webapp mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib cd ${DEV_HOME}/webapp
-
Copy in the jsps:
cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp
-
Copy in the jar file:
cp -rv ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar ${DEV_HOME}/webapp/WEB-INF/lib
-
Copy in the
web.xml
file:cp -rv ${DEV_HOME}/source/res/web.xml ${DEV_HOME}/webapp/WEB-INF
-
Create the war file:
jar cvf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war *
-
If this was successful you will now have a new file:
${DEV_HOME}/source/lib/javaBootcampNoEclipse.war
If this is the case, remove the direcory
${DEV_HOME}/webapp
and move on to lesson 4:rm -fr ${DEV_HOME}/webapp git checkout lesson-4
Lesson 4 – deploy and test
Starting point
A clean working area with two additional class files, one additional jar file and one additional war file.
Goal
A deployed, working application
Steps
-
Some pre-steps
- If this isn't the first time to deploy, be sure to undeploy the previous version of the application.
- Navigate to
http://server:8080/manager
- Go to the WAR file to deploy section and use the Browse… button to select the war file to deploy.
- Press the Deploy button. If successful, you'll see your application shown in the list.
- Go to
http://server:8080/javaBootcampNoEclipse
to access your app. -
Test the application. If all is well, move on to lesson 5:
git checkout lesson-5
Lesson 5 – Add new functionality
Starting point
A clean working brought up to date to include the two new files:
${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/Astro/AstroFun.java
and ${DEV_HOME}/source/lib/AstroLib-1.1.5ws.jar
, and an update
to
${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java
.
Goal
A working, updated application deployed to tomcat
Steps
-
Pre-steps
-
Make sure your environment is set up as per the previous lessons:
DEV_HOME
is set to where the git repository is cloned toCLASSPATH
containstomcat8-servlet-api.jar
-
Clean out the working area if there are unnecessary/unwanted files:
rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/*.class rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/Astro/*.class rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar rm -vfr ${DEV_HOME}/webapp
- Review the changes that have been applied to the working area
-
-
Compile the java files (including the new java file) as per Lesson 1.
Does it compile? If not, why. Three hints:
- there was a new sub-package added,
org.gibiris.javaBootcampNoEclipse.Astro
, which your java compiler needs to be able to find. - there was a new jar file introduced to the repository
- there's a bug in the package specification in the new java file. Looking closely at the branches of this git repository, you might even find a fix for it.
- there was a new sub-package added,
- Build the jar file as per Lesson 2 (except, this time, the
lib
directory exists already). - Build the war file as per Lesson 3.
- Deploy the updated application as per lesson 4. You will need to undeploy the previous version first. Does it deploy? Why not? (Hint: there was a new jar file introduced to the repository)
- Fix the new bug, undeploy the bad application and deploy the corrected one.