Compare commits

...

4 commits

Author SHA1 Message Date
350e549373 Improving the documentation 2017-08-13 00:08:50 +01:00
96664c2d5f Endint up where it all began 2017-08-12 22:57:18 +01:00
528d57851f A working script 2017-08-12 22:54:39 +01:00
553c3f29cb Bug fix: found the class
We need to specify the package the class is to be compiled for.
2017-08-12 22:16:32 +01:00
3 changed files with 244 additions and 60 deletions

View file

@ -7,7 +7,7 @@
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t #+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t #+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t #+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
#+CREATOR: Emacs 24.5.1 (Org mode 9.0) #+CREATOR:
#+DESCRIPTION: A java bootcamp module on building an app for tomcat with just the command-line #+DESCRIPTION: A java bootcamp module on building an app for tomcat with just the command-line
#+EXCLUDE_TAGS: noexport #+EXCLUDE_TAGS: noexport
#+KEYWORDS: #+KEYWORDS:
@ -19,12 +19,13 @@
** Pre-requisites ** Pre-requisites
You will need a linux server with the following installed: You will need a linux server with the following installed:
- tomcat :: This demo was prepare with tomcat-8. - tomcat :: This demo was prepare with tomcat-8.
- tomcat manager :: Used for deploying the your built application - tomcat manager :: Used for deploying your built application
- A web browser :: for accessing the tomcat manager - A web browser :: For accessing the tomcat manager
- git :: to access the project - git :: To access the project
- a text editor :: to fix any bugs you find (*Not* =eclipse=, - a text editor :: To fix any bugs you find (*Don't* use =eclipse=,
because that's the whole point.) or any other "IDE", because that's the whole point.)
- java 8 JDK :: to build code - java 8 JDK :: To build code
If you develop on one machine and deploy to the other, then If you develop on one machine and deploy to the other, then
*tomcat* and *tomcat manager* are to be on the system you're *tomcat* and *tomcat manager* are to be on the system you're
deploying to, and the rest where you're developing. deploying to, and the rest where you're developing.
@ -39,7 +40,8 @@
where the git repository has been cloned to. where the git repository has been cloned to.
1. Get the code 1. Get the code
: git clone https://gitlab.com/eibhear/javaBootcampNoEclipse.git : git clone https://gitlab.com/eibhear/javaBootcampNoEclipse.git
The repository is now in =${DEV_HOME}=. Change into it: The repository is now in =${DEV_HOME}=. Set that as an
environment variable and change into it:
: export DEV_HOME=$(pwd)/javaBootcampNoEclipse : export DEV_HOME=$(pwd)/javaBootcampNoEclipse
: cd ${DEV_HOME} : cd ${DEV_HOME}
2. Make sure you're at the starting point: 2. Make sure you're at the starting point:
@ -56,47 +58,53 @@
*** Steps *** Steps
0. [@0] Confirm you can access the java compiler: 0. [@0] Confirm you can access the java compiler:
: javac -version : javac -version
If this doesn't result in a message like =javac 1.8.0_141=, If this doesn't result in a message that looks something like
you'll need to find where =javac= installed and place it on =javac 1.8.0_141=, you'll need to find where =javac= is
your =${PATH}=. installed and place it on your =${PATH}=.
1. Change to where the code is: 1. Change to where the code is:
: cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse : cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse
2. Compile the files: 2. Compile the files:
: javac *.java : javac *.java
3. Check the errors. If you see the message =error: package 3. Check the errors. If you see the message
javax.servlet does not exist=, then look at your =CLASSPATH= : error: package javax.servlet does not exist
setting, as dependend libraries are missing. then look at your =CLASSPATH= setting, as dependent libraries
are missing.
4. Fix your =CLASSPATH= and compile the java files: 4. Fix your =CLASSPATH= and compile the java files:
: export CLASSPATH=/usr/share/java/tomcat8-servlet-api.jar:${CLASSPATH} : export CLASSPATH=/usr/share/java/tomcat8-servlet-api.jar:${CLASSPATH}
: javac *.java : javac *.java
5. If the successful, you will have the following additional files: 5. If successful, you will have the following additional files
: ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class under =${DEV_HOME}/source/java/=:
: ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class : org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
If this is the case, move on to lesson 2: If this is the case, move on to lesson 2:
: git checkout lesson-2 : git checkout lesson-2
** Lesson 2 -- build the jar file ** Lesson 2 -- build the jar file
*** Starting point *** Starting point
A clean git working area with two additional class files A clean git working area with two additional class files in
=${DEV_HOME}/source/java/=:
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
*** Goal *** Goal
Class files archived into a jar file Class files archived into a jar file
*** Steps *** Steps
1. Decide whether you want to include the source (=*.java=) files 1. Decide whether you want to include the source (=*.java=) files
in the jar file in the jar file.
2. Determine other files to be included in the jar file 2. Determine other files to be included in the jar file
(e.g. config files, property files, etc.) (e.g. config files, property files, etc.).
3. Change to the top-level of the package in the source: 3. Change to the top-level of the package in the source:
: cd ${DEV_HOME}/source/java : cd ${DEV_HOME}/source/java
Create the =lib/= directory to take the jar file: Create the =lib/= directory to take the jar file:
: mkdir -pv ../lib : mkdir -pv ../lib
If you're *not* including the source files in the jar: 4. If you're *not* including the source files in the jar:
: jar cvf ../lib/javaBootcampNoEclipse.jar org/gibiris/javaBootcampNoEclipse/*.class : jar cvf ../lib/javaBootcampNoEclipse.jar \
If you *are* including the source files in the jar: : org/gibiris/javaBootcampNoEclipse/*.class
: jar cvf ../lib/javaBootcampNoEclipse.jar org/gibiris/javaBootcampNoEclipse/* 5. If you *are* including the source files in the jar:
4. If the successful, you will now have a new file: : jar cvf ../lib/javaBootcampNoEclipse.jar org
6. If successful, you will now have a new file:
: ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar : ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar
If this is the case, move on to lesson 3: If this is the case, move on to lesson 3:
: git checkout lesson-3 : git checkout lesson-3
@ -104,8 +112,12 @@
** Lesson 3 -- build the war file ** Lesson 3 -- build the war file
*** Starting point *** Starting point
A clean git working area with two additional class files and one A clean git working area with two additional class files in
additional jar file. =${DEV_HOME}/source/java/=:
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
and one additional jar file in =${DEV_HOME}/source/lib/=:
: javaBootcampNoEclipse.jar
*** Goal *** Goal
A deployable war file A deployable war file
@ -113,64 +125,83 @@
*** Steps *** Steps
0. [@0] Review the following: 0. [@0] Review the following:
- http://tomcat.apache.org/tomcat-8.0-doc/appdev/deployment.html - http://tomcat.apache.org/tomcat-8.0-doc/appdev/deployment.html
to understand the structure of the =war= file and the to understand the structure of the file =web.xml= and the
=web.xml= file =war= file
- =${DEV_HOME}/source/res/web.xml= to understand how this - =${DEV_HOME}/source/res/web.xml= to understand how this
application is to be used. application is to be used
1. Create an empty directory in =${DEV_HOME}= called =webapp=, 1. Create an empty directory in =${DEV_HOME}= called =webapp=,
then its directory structure and then change into it: then its directory structure, and then change into it:
: mkdir -vp ${DEV_HOME}/webapp : mkdir -vp ${DEV_HOME}/webapp
: mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib : mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib
: cd ${DEV_HOME}/webapp : cd ${DEV_HOME}/webapp
2. Copy in the jsps: 2. Copy in the jsps:
: cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp : cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp
3. Copy in the jar file: 3. Copy in the jar file:
: cp -rv ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar ${DEV_HOME}/webapp/WEB-INF/lib : cp -rv ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar \
: ${DEV_HOME}/webapp/WEB-INF/lib
4. Copy in the =web.xml= file: 4. Copy in the =web.xml= file:
: cp -rv ${DEV_HOME}/source/res/web.xml ${DEV_HOME}/webapp/WEB-INF : cp -rv ${DEV_HOME}/source/res/web.xml \
: ${DEV_HOME}/webapp/WEB-INF
5. Create the war file: 5. Create the war file:
: jar cvf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war * : jar cvf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war *
6. If this was successful you will now have a new file: 6. If this was successful you will now have a new file:
: ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war : ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war
If this is the case, remove the direcory =${DEV_HOME}/webapp= 7. If this is the case, remove the direcory =${DEV_HOME}/webapp=
and move on to lesson 4: and move on to lesson 4:
: rm -fr ${DEV_HOME}/webapp : cd ${DEV_HOME}; rm -fr ${DEV_HOME}/webapp
: git checkout lesson-4 : git checkout lesson-4
** Lesson 4 -- deploy and test ** Lesson 4 -- deploy and test
*** Starting point *** Starting point
A clean working area with two additional class files, one 1. A clean working area with two additional class files in
additional jar file and one additional war file. =${DEV_HOME}/source/java/=:
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
one additional jar file and one additional war file, both in
=${DEV_HOME}/source/lib=:
: javaBootcampNoEclipse.jar
: javaBootcampNoEclipse.war
*** Goal *** Goal
A deployed, working application A working application
*** Steps *** Steps
0. [@0] Some pre-steps 0. [@0] Some pre-steps
- If this isn't the first time to deploy, be sure to /undeploy/ - If this isn't the first time to deploy, be sure to /undeploy/
the previous version of the application. the previous version of the application.
1. Navigate to =http://server:8080/manager= - To follow these steps, you'll need your file
=javaBootcampNoEclipse.war= to be accessible locally to your
browser.
1. Navigate to =http://server:8080/manager= (where =server= is
where your tomcat instance is running)
2. Go to the /WAR file to deploy/ section and use the /Browse.../ 2. Go to the /WAR file to deploy/ section and use the /Browse.../
button to select the war file to deploy. button to select the war file to deploy
(=javaBootcampNoEclipse.war=).
3. Press the /Deploy/ button. If successful, you'll see your 3. Press the /Deploy/ button. If successful, you'll see your
application shown in the list. application shown in the list.
4. Go to =http://server:8080/javaBootcampNoEclipse= to access your 4. Go to =http://server:8080/javaBootcampNoEclipse= to access your
app. app.
5. Test the application. If all is well, move on to lesson 5: 5. Test the application. If all is well, clean up your development
environment altogether:
: rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/*.class
: rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar
: rm -vfr ${DEV_HOME}/webapp
6. Move on to lesson 5:
: git checkout lesson-5 : git checkout lesson-5
** Lesson 5 -- Add new functionality ** Lesson 5 -- Add new functionality
*** Starting point *** Starting point
A clean working brought up to date to include the two new files: A clean working area, brought up to date to include the two new
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/Astro/AstroFun.java= files -- =Astro/AstroFun.java= in
and =${DEV_HOME}/source/lib/AstroLib-1.1.5ws.jar=, and an update =${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse= and
to =AstroLib-1.1.5ws.jar= in =${DEV_HOME}/source/lib= -- and an
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java=. update to =MyHelloWorldServlet.java= in
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse=.
*** Goal *** Goal
A working, updated application deployed to tomcat A working, updated application deployed to tomcat.
*** Steps *** Steps
0. [@0] Pre-steps 0. [@0] Pre-steps
@ -178,33 +209,42 @@
+ =DEV_HOME= is set to where the git repository is cloned to + =DEV_HOME= is set to where the git repository is cloned to
+ =CLASSPATH= contains =tomcat8-servlet-api.jar= + =CLASSPATH= contains =tomcat8-servlet-api.jar=
- Clean out the working area if there are unnecessary/unwanted files: - Clean out the working area if there are unnecessary/unwanted files:
: rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/*.class : cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse; \
: rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/Astro/*.class : rm -vf *.class; rm -vf Astro/*.class
: rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar : rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar
: rm -vfr ${DEV_HOME}/webapp : rm -vfr ${DEV_HOME}/webapp
- Review the changes that have been applied to the working area - Review the changes that have been applied to the working area
1. Compile the java files (including the new java file) as per 1. Compile the java files (including the new java file) as per
Lesson 1. /Lesson 1/.
Does it compile? If not, why. Three hints: Does it compile? If not, why not? Three hints:
- there was a new sub-package added, - There was a new sub-package added,
=org.gibiris.javaBootcampNoEclipse.Astro=, which your java =org.gibiris.javaBootcampNoEclipse.Astro=, which your java
compiler needs to be able to find. compiler needs to be able to find
- there was a new jar file introduced to the repository - There was a new jar file introduced to the repository
- there's a bug in the package specification in the new java - There's a bug in the package specification in the new java
file. Looking closely at the branches of this git repository, file. Looking closely at the branches of this git repository,
you might even find a fix for it. you might even find a fix for it.
2. Build the jar file as per Lesson 2 (except, this time, the 2. Build the jar file as per /Lesson 2/ (except, this time, the
=lib= directory exists already). =lib= directory exists already).
3. Build the war file as per Lesson 3. 3. Build the war file as per /Lesson 3/.
4. Deploy the updated application as per lesson 4. You will need 4. Deploy the updated application as per /Lesson 4/. You will need
to undeploy the previous version first. to undeploy the previous version first.
Does it deploy? Why not? (Hint: there was a new jar file Does it deploy? Why not? If it deploys, does it work? Why not?
introduced to the repository) (Hint: there was a new jar file introduced to the repository)
5. Fix the new bug, undeploy the bad application and deploy the 5. Fix the new bug, undeploy the bad application and deploy the
corrected one. corrected one.
** Fin
*Look closely. At last, you get to see an eclipse!*
Hint: what's happening[fn:longPast:... or "what /happened/" if it
has gone past] in Grand Island in Nebraska at ~13:00 local time on
[2017-08-21 Mon]?

View file

@ -1,3 +1,4 @@
package org.gibiris.javaBootcampNoEclipse.Astro;
import com.mhuss.AstroLib.*; import com.mhuss.AstroLib.*;
import com.mhuss.Util.*; import com.mhuss.Util.*;

143
source/scripts/allInOne.sh Executable file
View file

@ -0,0 +1,143 @@
#!/bin/bash
# This script (known as ${0} to itself) is in
# <somewhere>/source/scripts/, and we want to know where <somewhere>
# is without forcing a hard-coding on anyone. This is how we do that.
export DEV_HOME=$(cd $(dirname ${0})/../..; pwd)
# Go to our top-level development directory.
cd ${DEV_HOME}
# Checkout the lesson-4 tag (any of lesson-1, lesson-2, lesson-3 or
# lesson-4 would work just as well).
git checkout lesson-4
# Confirm we have a javac
javac -version
# If this doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Set the CLASSPATH
export CLASSPATH=/usr/share/java/tomcat8-servlet-api.jar:${CLASSPATH}
# Go to where the java source is
cd ${DEV_HOME}/source/java
# Compile them
javac org/gibiris/javaBootcampNoEclipse/*.java
# If this doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Confirm
ls -l org/gibiris/javaBootcampNoEclipse/*.class
# Prepare for the jar file
mkdir -pv ../lib
# We're going with including the source as well
jar cvf ../lib/javaBootcampNoEclipse.jar org
# If this doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Confirm
ls -l ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar
# Prepare for the war file (this command creates all the dirs we need
# created)
mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib
cd ${DEV_HOME}/webapp
# Copy the candidate files into place.
cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp
cp -rv ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar ${DEV_HOME}/webapp/WEB-INF/lib
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 doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Preserve the war file
mv -v ${DEV_HOME}/source/lib/javaBootcampNoEclipse{,-up-to-lesson-4}.war
# Clean up
cd ${DEV_HOME}
rm -vf ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/*.class
rm -vf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.?ar
rm -vfr ${DEV_HOME}/webapp
# Update the repository to get the changes
git checkout lesson-5-working
# We add the necessaries to the CLASSPATH
export CLASSPATH=${DEV_HOME}/source/lib/AstroLib-1.1.5ws.jar:${DEV_HOME}/source/java:${CLASSPATH}
# Go to where the source is
cd ${DEV_HOME}/source/java
# Compile them
javac org/gibiris/javaBootcampNoEclipse/*.java
# If this doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Confirm
ls -l org/gibiris/javaBootcampNoEclipse/*{,/*}.class
# Again, we're including the source as well
jar cvf ../lib/javaBootcampNoEclipse.jar org
# If this doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Confirm
ls -l ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar
# Prepare for the war file (this command creates all the dirs we need
# created)
mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib
cd ${DEV_HOME}/webapp
# Copy the candidate files into place, including the additional one.
cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp
cp -rv ${DEV_HOME}/source/lib/javaBootcampNoEclipse.jar ${DEV_HOME}/webapp/WEB-INF/lib
cp -rv ${DEV_HOME}/source/lib/AstroLib-1.1.5ws.jar ${DEV_HOME}/webapp/WEB-INF/lib
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 doesn't work, we'll stop here.
if [ ${?} -ne 0 ]; then
exit 1
fi
# Preserve the war file
mv -v ${DEV_HOME}/source/lib/javaBootcampNoEclipse{,-lesson-5}.war
cd ${DEV_HOME}
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
# Let's get back to where we started, git-wise
git checkout all-lessons-in-one-shell-script