Compare commits

..

1 commit

Author SHA1 Message Date
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
5 changed files with 62 additions and 402 deletions

View file

@ -7,7 +7,7 @@
#+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: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
#+CREATOR:
#+CREATOR: Emacs 24.5.1 (Org mode 9.0)
#+DESCRIPTION: A java bootcamp module on building an app for tomcat with just the command-line
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
@ -16,48 +16,15 @@
* Dude! Where's my Eclipse
** Introduction
From time to time, a developer will be in a situation where code
needs to be fixed, but there isn't a familiar IDE available.
Similarly, in order to progress from developer to senior developer
and on to architect, it's important to understand not just what's
going on in the code, but also outside the code.
This module takes a simple java tomcat application and brings you
on a tour from compiling the java files, to creating a jar file and
then a war file and on to deploying the application, using just a
basic editor to make changes and the command-line to build the
relevant artefacts.
The goal is to give a flavour of what goes on behind the IDE so
that a developer can understand that taking a peek behind the
curtain from time-to-time is not just informative and interesting,
but is also of value to the goal of Making A Real Difference.
*** Examples
1. You've just discovered that there's a critical bug in the code,
but you got your new development PC last night and you haven't
had the chance to install your preferred IDE. You don't have
the time, but you know the integration test environment has the
correct JDK installed, so you can work there. Only problem:
it's a command-line only environment.
2. You're working on a bug but it can only be reproduced in the
test environment, where your IDE isn't installed. You need to
work on it there until the issue has been identified and you
know what the fix is going to be.
** 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 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 (*Don't* use =eclipse=,
or any other "IDE", because that's the whole point.)
- java 8 JDK :: To build code
- 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.
@ -72,8 +39,7 @@
where the git repository has been cloned to.
1. Get the code
: git clone https://gitlab.com/eibhear/javaBootcampNoEclipse.git
The repository is now in =${DEV_HOME}=. Set that as an
environment variable and change into it:
The repository is now in =${DEV_HOME}=. Change into it:
: export DEV_HOME=$(pwd)/javaBootcampNoEclipse
: cd ${DEV_HOME}
2. Make sure you're at the starting point:
@ -90,53 +56,47 @@
*** Steps
0. [@0] Confirm you can access the java compiler:
: javac -version
If this doesn't result in a message that looks something like
=javac 1.8.0_141=, you'll need to find where =javac= is
installed and place it on your =${PATH}=.
If this doesn't result in a message like =javac 1.8.0_141=,
you'll need to find where =javac= installed and place it on
your =${PATH}=.
1. Change to where the code is:
: cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse
2. Compile the files:
: javac *.java
3. Check the errors. If you see the message
: error: package javax.servlet does not exist
then look at your =CLASSPATH= setting, as dependent libraries
are missing.
3. Check the errors. If you see the message =error: package
javax.servlet does not exist=, then look at your =CLASSPATH=
setting, as dependend libraries are missing.
4. Fix your =CLASSPATH= and compile the java files:
: export CLASSPATH=/usr/share/java/tomcat8-servlet-api.jar:${CLASSPATH}
: javac *.java
5. If successful, you will have the following additional files
under =${DEV_HOME}/source/java/=:
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
5. 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 in
=${DEV_HOME}/source/java/=:
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldBean.class
: org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.class
A clean git working area with two additional class files
*** Goal
Class files archived into a jar file
*** Steps
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
(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:
: cd ${DEV_HOME}/source/java
Create the =lib/= directory to take the jar file:
: mkdir -pv ../lib
4. If you're *not* including the source files in the jar:
: jar cvf ../lib/javaBootcampNoEclipse.jar \
: org/gibiris/javaBootcampNoEclipse/*.class
5. If you *are* including the source files in the jar:
: jar cvf ../lib/javaBootcampNoEclipse.jar org
6. If successful, you will now have a new file:
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/*
4. 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
@ -144,12 +104,8 @@
** Lesson 3 -- build the war file
*** Starting point
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
and one additional jar file in =${DEV_HOME}/source/lib/=:
: javaBootcampNoEclipse.jar
A clean git working area with two additional class files and one
additional jar file.
*** Goal
A deployable war file
@ -157,83 +113,64 @@
*** Steps
0. [@0] Review the following:
- http://tomcat.apache.org/tomcat-8.0-doc/appdev/deployment.html
to understand the structure of the file =web.xml= and the
=war= file
to understand the structure of the =war= file and the
=web.xml= file
- =${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=,
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/WEB-INF/lib
: cd ${DEV_HOME}/webapp
2. Copy in the jsps:
: cp -rv ${DEV_HOME}/source/jsps/* ${DEV_HOME}/webapp
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:
: 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:
: jar cvf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war *
6. If this was successful you will now have a new file:
: ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war
7. If this is the case, remove the direcory =${DEV_HOME}/webapp=
If this is the case, remove the direcory =${DEV_HOME}/webapp=
and move on to lesson 4:
: cd ${DEV_HOME}; rm -fr ${DEV_HOME}/webapp
: rm -fr ${DEV_HOME}/webapp
: git checkout lesson-4
** Lesson 4 -- deploy and test
*** Starting point
1. A clean working area with two additional class files in
=${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
A clean working area with two additional class files, one
additional jar file and one additional war file.
*** Goal
A working application
A deployed, working application
*** Steps
0. [@0] Some pre-steps
- If this isn't the first time to deploy, be sure to /undeploy/
the previous version of the application.
- 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)
1. Navigate to =http://server:8080/manager=
2. Go to the /WAR file to deploy/ section and use the /Browse.../
button to select the war file to deploy
(=javaBootcampNoEclipse.war=).
button to select the war file to deploy.
3. Press the /Deploy/ button. If successful, you'll see your
application shown in the list.
4. Go to =http://server:8080/javaBootcampNoEclipse= to access your
app.
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:
5. 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 area, brought up to date to include the two new
files -- =Astro/AstroFun.java= in
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse= and
=AstroLib-1.1.5ws.jar= in =${DEV_HOME}/source/lib= -- and an
update to =MyHelloWorldServlet.java= in
=${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse=.
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.
A working, updated application deployed to tomcat
*** Steps
0. [@0] Pre-steps
@ -241,58 +178,33 @@
+ =DEV_HOME= is set to where the git repository is cloned to
+ =CLASSPATH= contains =tomcat8-servlet-api.jar=
- Clean out the working area if there are unnecessary/unwanted files:
: cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse; \
: rm -vf *.class; rm -vf Astro/*.class
: 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
1. Compile the java files (including the new java file) as per
/Lesson 1/.
Lesson 1.
: cd ${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse
: javac *.java
Does it compile? If not, why not? Three hints:
- There was a new sub-package added,
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
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.
2. Build the jar file as per /Lesson 2/ (except, this time, the
=lib= directory exists already):
2. Build the jar file as per Lesson 2 (except, this time, the
=lib= directory exists already).
: cd ${DEV_HOME}/source/java
: jar cvf ../lib/javaBootcampNoEclipse.jar org
3. Build the war file as per Lesson 3.
3. Build the war file as per /Lesson 3/.
: mkdir -vp ${DEV_HOME}/webapp
: mkdir -vp ${DEV_HOME}/webapp/WEB-INF/lib
: cd ${DEV_HOME}/webapp
: 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
: jar cvf ${DEV_HOME}/source/lib/javaBootcampNoEclipse.war *
: cd ${DEV_HOME}; rm -fr ${DEV_HOME}/webapp
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.
Does it deploy? Why not? If it deploys, does it work? Why not?
(Hint: there was a new jar file introduced to the repository)
Does it deploy? Why not? (Hint: there was a new jar file
introduced to the repository)
5. Fix the new bug, undeploy the bad application and deploy the
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]?

Binary file not shown.

View file

@ -1,253 +0,0 @@
#+TITLE: Setup [Dude! Where's my Eclipse!?]
#+DATE: [2017-08-15 Tue]
#+AUTHOR: Éibhear Ó hAnluain, Version 1
#+EMAIL: eibhear.ohanluain@version1.com
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:{} arch:headline
#+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: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
#+CREATOR:
#+DESCRIPTION: How to set up an environment to facilitate the preparation and presentation of the "Dude! Where's my Eclipse!?" java bootcamp module.
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
* Setup [Dude! Where's my Eclipse]
** Introduction
This document outlines how to prepare an environment that you can
use to work on or give the presentation made available at
https://gitlab.com/eibhear/javaBootcampNoEclipse/.
If you are unable to follow these instructions precisely, you could
contact the author.
*** Assumptions
1. You can easily create and destroy a basic Linux VM, such as is
possible with an account on Amazon's AWS or Microsoft's Azure.
2. If the specific versions of packages or OS's mentioned below
are not available to you, you are able to get and use
appropriate alternatives.
*** Software
The following OS and package versions were used in the preparation
and presentation of this module:
- Debian Linux 9.1 (installed using the image file
=debian-9.1.0-amd64-netinst.iso=, as downloaded
https://cdimage.debian.org/)
- Tomcat 8 (including the Tomcat 8 Manager (=tomcat8-admin=))
- OpenJDK-8 JDK
- =git= (any version) needed to interact with the
code/presentation.
All other tools and utilities mentioned in this document were
installed to support the preparation and presentation of the
module. For each one, you may decide to use an alternative package
or take a different approach.
- =aptitude= :: The author prefers this to =apt-get=.
- =sudo= :: To allow for administration actions on the VM.
- =openssh-server= :: To facilitate inbound connections to the
command-line.
- =curl=, =wget=, =links= :: Useful, text-based, web client tools.
- =emacs-nox=, =magit= :: Development tools. GNU/Emacs to edit
files, =magit= to interact with the git repository through
=emacs=.
*** Other Notes
- The package =tomcat8-docs= was /not/ installed as it seemed to
break tomcat in a way that the author hadn't time to investigate
and fix.
- The author wanted to use the command-line to deploy the
application into the tomcat instance, but, again, all attempts
broke tomcat in a way that was going to be costly to investigate
and fix, so therefore we conceded the =manager-gui= for this.
If you are aware of this behaviour in tomcat, you might contact
the author with information on what may have been the problem(s).
** Setup
*** OS
The VM was built as a Debian GNU/Linux server, release 9.1
(/Jessie/). The only note-worthy comment on the installation is
that when asked for what software to install, none was selected
(i.e. the default options were de-selected -- debian installs
mandatory packages to give you a working server; when you're asked
to select software to install, these are to be /additional/
packages). This resulted in a base, headless system, which was
then configured according to the script below.
*** Configuration
The following shell script was executed by the user =root= once
the VM build was completed to configure the environment for this
presentation. Prior to running this script, you will need to make
the following edits to the script:
- Replace the two instances of =%%normal_user%%= with the username
of the user you provided during the installation. This will
allow that user to perform admin actions.
- Replace =%%tomcat_manager_password%%= with a password to be used
with the username =tomcat= to access the =/manager= application.
#+BEGIN_SRC sh
#!/bin/bash
# Needed to use aptitude
echo "apt-get install -y aptitude"
apt-get install -y aptitude
# Needed to give the normal admin access.
echo "aptitude install -y sudo "
aptitude install -y sudo
# Needed for basic inbound connectivity
echo "aptitude install -y openssh-server"
aptitude install -y openssh-server
# Needed for local and outbound connectivity testing
echo "aptitude install -y curl wget links"
aptitude install -y curl wget links
# Needed for simple development activity
echo "aptitude install -y git emacs-nox magit openjdk-8-jdk"
aptitude install -y git emacs-nox magit openjdk-8-jdk
# needed to test with tomcat
echo "aptitude install -y tomcat8 tomcat8-admin"
aptitude install -y tomcat8 tomcat8-admin
# Allow the user to perform admin actions.
echo "usermod -a -G sudo %%normal_user%%"
usermod -a -G sudo %%normal_user%%
# This allows access to the tomcat manager module. See
# http://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html
# for further information.
echo "Building /var/lib/tomcat8/conf/tomcat-users.xml"
cat << EOF > /var/lib/tomcat8/conf/tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary. It is
strongly recommended that you do NOT use one of the users in the commented out
section below since they are intended for use with the examples web
application.
-->
<!--
NOTE: The sample user and role entries below are intended for use with the
examples web application. They are wrapped in a comment and thus are ignored
when reading this file. If you wish to configure these users for use with the
examples web application, do not forget to remove the <!.. ..> that surrounds
them. You will also need to set the passwords to something appropriate.
-->
<role rolename="manager-gui"/>
<user username="tomcat" password="%%tomcat_manager_password%%" roles="manager-gui"/>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
</tomcat-users>
EOF
# Needed to allow access to the tomcat manager module from outside the
# local VM (so that you can connect from a different PC/server).
echo "Building /usr/share/tomcat8-admin/manager/META-INF/context.xml"
cat << EOF > /usr/share/tomcat8-admin/manager/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow=".*" />
</Context>
EOF
# Restarting tomcat, to be sure, to be sure.
echo "service tomcat8 restart"
service tomcat8 restart
#+END_SRC
*** Testing
To ensure all is set up correctly...
1) Review the output of the script above to see if there are any
errors.
2) You should be able to connect to your VM using =ssh= as your
configured user:
: ssh <username>@<vmNameOrIP>
3) You should be able to run the =sudo= command to perform admin
activities. For example, the following command will present
your VM's nework routing table. You should be logged in as your
"normal user" and you will be required to provide its password
(i.e. /not/ root's password).
: sudo route
4) You should be able to access the following URLs from within
your VM (shown here as calls to the =links= utility):
- tomcat
: links http://localhost:8080/
- tomcat manager
: links http://localhost:8080/manager/html
5) You should be able to access these same URLs from a remote
location (e.g. your desktop PC).
If this doesn't work, it may not be related to your VM
configuration, but to the network access controls between the
remote location and your VM. For example, if there is a
firewall between the two machines, you'll have to get past it.
6) Test the module itself (these commands assume you are logged
onto the VM as a normal user):
: mkdir -pv ${HOME}/development
: cd ${HOME}/development
: git clone https://gitlab.com/eibhear/javaBootcampNoEclipse.git
: cd ${HOME}/development/javaBootcampNoEclipse
: git checkout all-lessons-in-one-shell-script
: ${HOME}/development/javaBootcampNoEclipse/source/scripts/allInOne.sh
If all is well, there will be two new files in
=.../source/lib/=, =javaBootcampNoEclipse-up-to-lesson-4.war=
and =javaBootcampNoEclipse-lesson-5.war=. Deploy one or both of
these war files to tomcat using
=http://<vmNameOrIP>:8080/manager/html= to test them they
should both work without issue.
If all is well, you're in a position to work with the code
provided in the module or even to present it.

Binary file not shown.

View file

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