diff --git a/docs/javaBootcampNoEclipse.org b/docs/javaBootcampNoEclipse.org index 6bdb3d5..b094a0a 100644 --- a/docs/javaBootcampNoEclipse.org +++ b/docs/javaBootcampNoEclipse.org @@ -46,7 +46,7 @@ : git checkout lesson-1 ** Lesson 1 -- compile the code. - + *** Starting point A clean git working area @@ -159,3 +159,48 @@ app. 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 brought up to date to include the two new files: + =${DEV_HOME}/source/java/org/gibiris/javaBootcampNoEclipse/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 + 0. [@0] 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 to + + =CLASSPATH= contains =tomcat8-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/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. + + Does it compile? If not, why. Two hints: + - 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). + + 3. Build the war file as per Lesson 3. + + 4. 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) + + 5. Fix the new bug, undeploy the bad application and deploy the + corrected one. diff --git a/source/java/org/gibiris/javaBootcampNoEclipse/AstroFun.java b/source/java/org/gibiris/javaBootcampNoEclipse/AstroFun.java new file mode 100644 index 0000000..da36b8d --- /dev/null +++ b/source/java/org/gibiris/javaBootcampNoEclipse/AstroFun.java @@ -0,0 +1,94 @@ + +import com.mhuss.AstroLib.*; +import com.mhuss.Util.*; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.Date; + + +public class AstroFun { + + private double lat, lon; + private ObsInfo whereAmI; + private AstroDate myAD; + private PlanetData sunData, moonData; + + public AstroFun() { + + // Grand Island, Nebraska, U.S.A. + this.lat = 40.9162; + this.lon = -98.2962; + this.whereAmI = new ObsInfo (new Latitude(lat), new Longitude(lon)); + + // 2017-08-21 13:00 CDT + this.myAD = new AstroDate ( 21, 8, 2017, 21, 14, 0 ); + + this.sunData = new PlanetData (Planets.SUN, myAD.jd(), whereAmI); + + this.moonData = new PlanetData (Planets.LUNA, myAD.jd(), whereAmI); + } + + public double getSunD() { + double tmp; + try { + tmp = this.sunData.getDeclination(); + } + catch ( NoInitException nieOops ) { + tmp = 0; + } + return tmp; + } + + public double getSunRA() { + double tmp; + try { + tmp = this.sunData.getRightAscension(); + } + catch ( NoInitException nieOops ) { + tmp = 0; + } + return tmp; + } + + public double getMoonD() { + double tmp; + try { + tmp = this.moonData.getDeclination(); + } + catch ( NoInitException nieOops ) { + tmp = 0; + } + return tmp; + } + + public double getMoonRA() { + double tmp; + try { + tmp = this.moonData.getRightAscension(); + } + catch ( NoInitException nieOops ) { + tmp = 0; + } + return tmp; + } + + public static void main(String[] args) { + // System.out.println("Hello World!"); + + AstroFun hmm = new AstroFun(); + + System.out.print ("Sun: "); + System.out.println + ( "Declination: " + Math.toDegrees(hmm.getSunD()) + + ", Right Ascension: " + Math.toDegrees(hmm.getSunRA()) + ); + System.out.print ("Moon: "); + System.out.println + ( "Declination: " + Math.toDegrees(hmm.getMoonD()) + + ", Right Ascension: " + Math.toDegrees(hmm.getMoonRA()) + ); + + } + +} diff --git a/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java b/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java index 62029fa..4e7b59f 100644 --- a/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java +++ b/source/java/org/gibiris/javaBootcampNoEclipse/MyHelloWorldServlet.java @@ -9,6 +9,18 @@ public class MyHelloWorldServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + + double sunD = 0, sunRA = 0, moonD = 0, moonRA = 0; + + String oopsMsg = new String ("No exception"); + + AstroFun myAstroInfo = new AstroFun(); + + sunD = Math.toDegrees(myAstroInfo.getSunD()); + sunRA = Math.toDegrees(myAstroInfo.getSunRA()); + moonD = Math.toDegrees(myAstroInfo.getMoonD()); + moonRA = Math.toDegrees(myAstroInfo.getMoonRA()); + response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); @@ -18,6 +30,19 @@ public class MyHelloWorldServlet extends HttpServlet { out.println(""); out.println("

Éibhear's Hello World (Servlet) example

"); out.println("

Ho there!

"); + if ( oopsMsg.equals("No exception") ) { + out.println("

Position in the sky of the Sun and the Moon as seen from Grand " + + "Island in Nebraska on Monday the 21st of August at 21:14 " + + "UTC.

"); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println("
BodyDeclination (degrees N of equator)Right Ascension (degrees E of the Vernal Equinox)
Sun" + sunD + "" + sunRA + "
Moon" + moonD + "" + moonRA + "
"); + } + else { + out.println("

We regret to say that we can't bring you the information you're looking for at the moment. Please come back later (because, y'know, your visit is important to us, 'n' all!).

"); + } out.println(""); out.println(""); } diff --git a/source/lib/AstroLib-1.1.5ws.jar b/source/lib/AstroLib-1.1.5ws.jar new file mode 100644 index 0000000..bfb1ff6 Binary files /dev/null and b/source/lib/AstroLib-1.1.5ws.jar differ