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
6 changed files with 145 additions and 302 deletions

View file

@ -16,38 +16,6 @@
* 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.
@ -249,9 +217,6 @@
1. Compile the java files (including the new java file) as per
/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,
=org.gibiris.javaBootcampNoEclipse.Astro=, which your java
@ -262,22 +227,9 @@
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):
: cd ${DEV_HOME}/source/java
: jar cvf ../lib/javaBootcampNoEclipse.jar org
=lib= directory exists already).
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
to undeploy the previous version first.

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.*;

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