Skip to content

Lycbel/Java

Repository files navigation

Basic Maven, JSP, and JDBC

Due by 11:59pm CDT,?Monday?September 11, 2017 (Extension allowed:?11:59pm CDT,?Wednesday?September 13, 2017)


Objectives

  • Automate build using scripts and Maven
  • Familiar yourself with the Java web application development you will be using for iTrust project this semester

Goal

In this MP, you will be automating how you compile your Java code, using both a Bash script and Maven. Also, you will be getting?familiar with Java web application (webapp) development technology?you will be using for iTrust project this semester.

You can do this MP on your own machine or on the VM, but we will only be grading what you commit to your Git repository, and we will be running on a VM (identical to the one you are assigned). It is in your best interest to make sure your code, tests, and scripts work on your VM.?(If you edit on another platform, you may run into end-of-line problems that you will have to debug.)

Getting the Code

We have prepared some starting files that you can use:?CoffeeMaker_Web.tgz?and?CoffeeMaker_WebDB.tgz

Unzip this tarball under your?cs427fa17/mp1?in your Gitlab repository, so that it is located at?https://gitlab.engr.illinois.edu/<netID>/cs427fa17/tree/master/mp1/CoffeeMaker_Web and https://gitlab.engr.illinois.edu/<netID>/cs427fa17/tree/master/mp1/CoffeeMaker_WebDB:

$ tar xzf CoffeeMaker_Web.tgz
$ tar xzf CoffeeMaker_WebDB.tgz

You will work under these two directories for this MP1.

Each directory will contain the starting source code files in?src/main/java and src/main/webapp, and the Maven build script pom.xml, which is the common Maven layout.


Exercise 1: Building and Deploying

The objective of this exercise is for you to learn what commands automate?build a simple Java webapp project.

You will be automating your build in two ways. The first way is a Bash script that details all the steps that go in a build. The goal is for you to understand what IntelliJ or Maven do "automagically". The second way is a Maven build script that is a much more proper way to do a build than via a Bash script.

You will be adding and committing into your repository a single file:?build.sh

For this exercise, you will work under CoffeMaker_Web directory only.

Building with Script

Write a Bash script called?build.sh?that can compile your CoffeeMaker_Web project. You should first write the script and put it into your local directory (cs427fa17/mp1/CoffeeMaker_Web), and then commit and push the script so that it is located at https://gitlab.engr.illinois.edu/<netID>/cs427fa17/blob/master/mp1/CoffeeMaker_Web/build.sh.

The script is supposed to be executed under CoffeeMaker_Web directory.

The script must do the following:

  1. Compile Java sources using javac:
    1. Create a directory?target/CoffeeMaker_Web/WEB-INF/classes/?under your local?CoffeeMaker_Web?directory (please?DO NOT?commit?target?to the repo! Consider adding it to your?gitignore?file?to ignore?target).
    2. Compile the java source files in src/main/java using javac.

    3. Copy the compiled .class files into the directory you created in the previous step,?target/CoffeeMaker_Web/WEB-INF/classes/. (Hint: consider whether your classes are in the right directory based on their package.)
  2. Copy JSP sources:
    1. Copy the JSP source files in src/main/webapp into?target/CoffeeMaker_Web.
    2. Copy?src/main/webapp/WEB-INF/web.xml file into?target/CoffeeMaker_Web/WEB-INF.
  3. Package in WAR file:
    1. Ensure?target/CoffeeMaker_Web directory is correctly structued: ("*" refers to multiple file names.)

      target/CoffeeMaker_Web/WEB-INF/classes/edu/ncsu/csc326/coffeemaker/*.class
      target/CoffeeMaker_Web/WEB-INF/classes/edu/ncsu/csc326/coffeemaker/exceptions/*.class
      target/CoffeeMaker_Web/WEB-INF/web.xml
      target/CoffeeMaker_Web/*.jsp
      
    2. Pakage (i.e., archive) target/CoffeeMaker_Web in WAR format:

      $ cd target/CoffeeMaker_Web
      $ jar -cvf ../CoffeeMaker_Web.war *

git add?build.sh?into the?cs427fa17/mp1/CoffeeMaker_Web/?directory and commit it.

To get full credit for your script, it must successfully compile your Java files into .class files and package them in WAR format.?We will be grading your work by?running your?build.sh?script on a clean VM. Of course, you can safely assume that the prerequisites required in MP0 (e.g., JDK, Maven, and Tomcat)?are already installed in the clean VM. You are encouraged to test in a similar environment.

NOTE: the goal of the build.sh script is to only?build the target/CoffeeMaker_Web.war?file, but?not?to deploy it. The deployment described below is optional just for you to make sure your built WAR file is correct. The build.sh should?NOT?deploy the webapp, start up Tomcat, nor open a browser.


You can check if your build script works correctly by deploying the WAR file created by the script as follows. (We will also use this method to grade your script.) NOTE:?the below is not what the build.sh is supposed to do.

Deploy WAR file on Tomcat

  1. Set up the environment variable?CATALINA_HOME to the tomcat directory that you install in MP0:

    $ export CATALINA_HOME=/path/to/apache-tomcat-9.0.0.M26
  2. Copy the WAR file created by the script into $CATALINA_HOME/webapps directory.
  3. Start up Tomcat:

    $ $CATALINA_HOME/bin/startup.sh
  4. Open the page?http://localhost:8080/CoffeeMaker_Web/?in your web browser (within the same machine?where Tomcat is deployed), and test the webapp. If you want to open the page from a different machine, then replace "localhost" with the address to the machine in which Tomcat is deploed. For example, if you deployed Tomcat in the VM, and want to open the page from your own machine, then access?http://fa17-cs427-XYZ.cs.illinois.edu:8080/CoffeeMaker_Web/ (where XYZ is your VM ID).

  5. Shutdown Tomcat once you've done with the testing:

    $ $CATALINA_HOME/bin/shutdown.sh

Building with Maven

The above build and deploy tasks can be done by simply running the Maven build script pom.xml with proper commands.

You can compile the Java source files and package the webapp in a WAR file by running the following command?under the?cs427fa17/mp1/CoffeeMaker_Web?directory:

$ mvn package

The above command will create?target/CoffeeMaker_Web.war, which you can manually deploy on Tomcat as described in the previous paragraph.

Alternatively, you can quickly deploy your webapp by running the following command under the same directory:

$ mvn tomcat7:run


(Optional) IntelliJ Setup

Select "Import Project" in the Welcome screen, or "File" > "New" > "Project from Existing Sources..." in the menu. Select the pom.xml file in CoffeeMaker_Web directory that you downloaded and uncompressed. Select the default options (just keep clicking "Next" buttons until "Finish"). Select "Edit Configurations..." in "Run" menu. Select "Tomcat Server" / "Local" configuration. Name it "CoffeeMaker_Web". Select?"Deployment" tab and click "+" button to add the artifact "CoffeeMaker_Web:war". Edit?"Application context"?to be "/CoffeeMaker_Web". Click "Apply" to finish the configuration setting. Now click "Run" button, which will build and deploy the webapp.


Exercise 2: JSP

Complete the?JSP tutorial. For the starting source code, use?cs427fa17/mp1/CoffeeMaker_Web?that you downloaded in the beginning. Do NOT use the one provided in the tutorial.?For this exercise, you will work under CoffeMaker_Web directory only.?

Modify?edit_recipe.jsp and?add_inventory.jsp?as the intruction of the tutorial exercise. Use?add_inventory.jsp?file provided as a skeleton. Do NOT?create your own?add_inventory.jsp file.


Create?jsp_answers.txt?file and put it under cs427fa17/mp1/CoffeeMaker_Web. ?See NOTES below for the format of the file.

Do NOT modify other files. They will be ignored and replaced with the original files when your code is graded.

You can check if your code works correctly by running the (Selenium) integration test,?src/test/java/edu/ncsu/csc326/coffeemaker/ITMain.java,?as follows. You can expect to get the full score once your code passes the test.

Running Selenium integration test

You have two ways to run the Selenium interation test ITMain.java.

  1. Using Maven
    1. Build and deploy the webapp:

      $ mvn package tomcat7:run
    2. Run the test: (you will need to open another terminal to run the following command, since the above command is blocking.)

      $ mvn -Dtest=ITMain test
  2. Using IntelliJ
    1. Build and deploy the webapp:
      Run "CoffeeMaker_Web" configuration.
    2. Run the test:
      Navigate the ITMain.java file in the Project source tree. Right-click and select "Run 'ITMain'".

NOTES:?

  • Use the starting source files?CoffeeMaker_Web.tgz?instead of the one linked in the tutorial, and deploy it as described in Exercise 1.
  • Use the skeleton add_inventory.jsp file provided in?CoffeeMaker_Web.tgz?to complete the AddInventory user story.?Do?not?create your own?add_inventory.jsp?file.
  • Do not modify ITMain.java?file. We will use the original test file when grading your work.
  • Locate?src/main/webapp?for?WebContent mentioned in the tutorial.
  • "The?setAttribute()?method always returns an Object;" in the tutorial should be??"The?getAttribute()?method always returns an Object;".
  • In the source code of?CoffeeMaker_Web,?the JavaDoc comment for?addInventory() in the?CoffeeMaker class: "Returns?true if inventory was successfully added" should be "Returns?void".
  • "Create a file named "jsp_answers_unityid.txt" (where?unityid?is your?unity?id)"?in the tutorial?should be "Create a file named "jsp_answers.txt".
    • Format: the file should consists of two lines of text, one for each code snippet's output. Each of the output should be either "Nothing" or "JSP is fun". So, for example, the "jsp_answers.txt" file should looks like as follows:

      Nothing
      JSP is fun


Complete the?JDBC tutorial.?For the starting source code, use?cs427fa17/mp1/CoffeeMaker_WebDB?that you downloaded in the beginning. Do NOT use the one provided in the tutorial.?For this exercise, you will work under CoffeMaker_WebDB directory only.?

Create?InventoryDB.java file and update?Inventory.java file as intructed in the tutorial. Use add_inventory.jsp that you have developed in Exercise 2.
You can check if your code works correctly by running the (Selenium) integration test?src/test/java/edu/ncsu/csc326/coffeemaker/ITMain.java?as described in Exercise 2. You will get the full score once your code 1) passes the test and 2) does not?have the static fields (coffee, milk, sugar, and chololate) in Inventory.java.

NOTES:?

  • Use this source files?CoffeeMaker_WebDB.tgz?instead of the one linked in the tutorial, and deploy it similarly as described in Exercise 1.
  • Edit?META-INF/context.xml file if your MySQL root password is anything other than an empty string.
  • Ignore the section "2.0 Getting Started" in the tutorial, but follow the build & deployment instructions described in Exercise 1.
  • addInventory() should add inventory to the coffee maker, ?useInventory()?should expend the inventory after making coffee, and checkInventory() should display the amounts of each item that the coffee maker has.?The purpose of this assignment is to write these methods such that the code uses the database to keep track of the inventory. The learning object of this tutorial is to?make sure you understand correct SQL syntax and how to interact with the database tables.


Deliverables


Make sure that you submit (git commit and push) the following required files. We will look for only those files to grade your code; other files will be ignored and simply replaced with the original ones provided in the starting source code.


We want to emphasize again that?

  1. You should make sure to add, commit and push all your changes, and that your code in the Gitlab repo is the version we are looking for. Your code must compile and you need to include all of the required files. Non-compilable code = 0. However, DO NOT add any target binary files to the repository.
  2. Your code must work on VM (where the prerequisites required in MP0?(e.g., JDK, Maven, and Tomcat)?are installed).
  • No labels
Overview
Content Tools
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-73205543-2', {'siteSpeedSampleRate': 50}); ga('set', 'anonymizeIp', true) ga('send', 'pageview'); </script>

{"serverDuration": 105, "requestCorrelationId": "47db5b86db3862f2"}

<script type="text/javascript"> AJS.BigPipe = AJS.BigPipe || {}; AJS.BigPipe.metrics = AJS.BigPipe.metrics || {}; AJS.BigPipe.metrics.pageEnd = typeof window.performance !== "undefined" && typeof window.performance.now === "function" ? Math.ceil(window.performance.now()) : 0; AJS.BigPipe.metrics.isBigPipeEnabled = 'false' === 'true'; </script>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors