os dev tool box
TRANSCRIPT
Keys To Success
The key to proper debugging is a well set up environment! You might have most of this already installed on your machine.Use the information on the following slides to get your machine ready to rock
Prerequisites / Recommendations
OSX● At least one CLI
package managero brewo macports
● iTerm2*o Better
Terminal App● OSX Command
Line Tools*
It is assumed that the you have some of the following installed on your machine based on OS:
Windows● tar / rar extractor
o WinRar*● Access to cmd● PowerShell*● Cygwin*
*Not required for this presentation but highly recommended because of added features and usability
Prerequisites / Recommendations
We’re going to install the following applications on your machine:● Git● Vim● Java / JDK● Tomcat● Maven● PSI Probe (Tomcat Webapp)
If you have them already installed, feel free to skip the section and continue on to the next
Installing git: Linux
● Debian based distros:$ sudo apt-get install git
● RedHat based distros:$ sudo yum install git-core
Installing git: Windows
Grab the latest version of git for Windows http://git-scm.com/downloads
Nothing special, just use the default options when installing
Installing vim: Linux
vim might already be installed, but if not:● Debian based distros:
$ sudo apt-get install vim
● RedHat based distros:$ sudo yum install vim
Installing vim: Windows
*Cygwin provides many GNU and FOSS tools, which provide functionality similar to a Linux Distro to Windows.*Many of these tools have been provided with the installation of git-bash and are not required to install
There are a few options1.Use the one that comes with git-bash
● highly recommended2.gVim
● More GUI friendly3.Cygwin*
● More complicated setup
Installing java: Linux
● Debian based distros:$ sudo apt-get install openjdk-7-jdk
● RedHat based distros:$ sudo yum install \java-1.7.0-openjdk-devel
Installing java: Mac OSX
Java is installed by default on OSX● Installing Java 7 on OSX● Update Java on OSX● Java FAQs on OSX
Edit ~/.bashrc or ~/.zshrcCreate new variable JAVA_HOME and point to the install of java.
Example:export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64http://www.wikihow.com/Set-Up-Your-Java_Home-Path-in-Ubuntu
Setting up java: Linux and Mac OSX
Open JDK on Windows is not very well supported. Unofficial Build:https://github.com/alexkasko/openjdk-unofficial-builds#openjdk-unofficial-installers-for-windows-linux-and-mac-os-x
While this is a FOSS based presentation, we HIGHLY RECOMMEND Oracle JDK for Windowshttp://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html
Installing java: Windows
Installing Tomcat and Maven
Tomcat 7: https://tomcat.apache.org/download-70.cgi
Maven 3 : https://maven.apache.org/download.cgi
Download the latest zip versionTomcat 7.0.53 / Maven 3.2.1
Extract both to a folder, ie:Linux* / OSX*: $HOME/awesomepres/tomcat Windows: %USERPROFILE%\awesomepres\tomcat
*It is possible to install these through a package manager (apt / yum / brew / etc) we believe it is better to install these application yourself
Installing Tomcat: Linux and Mac OSX
Edit your ~/.bashrc or ~/.zshrc file to add tomcat bin directory path to PATH and add TOMCAT_HOME variable
Exampleexport TOMCAT_HOME=/path/to/tomcatexport M2_HOME=/path/to/mavenexport PATH=${PATH}:${TOMCAT_HOME}/bin:${M2_HOME}/bin
Setting Up Tomcat: Windows
Add path to tomcat’s bin folder to Windows PATH environment variable. http://www.computerhope.com/issues/ch000549.htm
Create TOMCAT_HOME environment variablehttp://www.howtogeek.com/51807/how-to-create-and-use-global-system-environment-variables/
Installing Maven (Cross Platform)
Maven provides excellent documentation for installing on all operating systemshttp://maven.apache.org/download.cgi#Installation
Installing Psi-Probe (Cross Platform)
Psi-probe is a manager for Tomcathttps://code.google.com/p/psi-probe/downloads/list
2. Move the probe.war file to Tomcat’s webapps directory
Psi-Probe
$ mv probe.war $TOMCAT_HOME/webapps
$ unzip probe-2.3.3.zip
1. Unzip the downloaded file
Installing meld: Linux
● Debian based distros:o sudo apt-get install meld
● RedHat based distros:o http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/meld.
html
Installing meld: Mac OSX
X11 is required to install meldX11 is no longer included with OSX● X11 Installation Instructions
Install using brew$ brew update$ brew install meld
Installing meld: Windows
http://meldmerge.org/
The version for Windows is not yet official but it still works great.
BREAK TIME!
We just installed aton of stuff, letstake a breakfor a bit and go stretch yourlegs, then return!
Setting up git (Cross Platform)
Setup your identity and editor:http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
Setting up GitHub
Create an account on GitHub
Follow the GitHub SSH key guide to setup SSH keys to be more secure!
Create a repository on GitHub
VIMTUTOR (FOR VIM BEGINNERS ONLY)
This is one of the best ways tolearn vim. Do lessons 1 through 3.Anything else is more advanced. On Linux and Mac:$ vimtutor
The vimtutor file is available here Hosted by digital ocean for Windows users to use.$ vim tutor
Feel free to skip this if you understand the basics
of vim
COFFEE BREAK TIME!!!!!!!!!!!
Take another break before tackling the homework. I would if I were you….
Homework!Fork our repository on GitHub to start the homework. Need help forking? Check out GitHub’s guide on that.
Time to use everything we just worked on!
Assignment #1
If you’ve never used git before, go through the following steps to create a basic repo and start getting your hands dirty using git.
https://help.github.com/articles/create-a-repo
Assignment #2
Fork our repository and clone the fork.
Need help?GitHub’s guide to forking and cloning is your friend
Assignment #2 Cont
Step one is to compile the web application and deploy it.$ cd SpringUrlShortner
Changes the directory to the repository we cloned$ mvn clean package
Runs maven to compile the package$ cp target/SpringUrlShortner.war $TOMCAT_HOME/webapps
Deploys the war file to tomcat
Assignment #2 Cont
Now let’s start up tomcat and view the page$ $TOMCAT_HOME/bin/startup.sh
Starts tomcat$ tail -f $TOMCAT_HOME/logs/catalina.out
Run this immediately after the previous command to watch for errors as Tomcat starts up. tail allows us to view the tomcat log file to see when the server is started up. Adding the option f to tail allows us to output appended data as the file grows. Control + c will exit out of a tail -f.
Assignment #2 ContThis is what we get when we view http://localhost:8080/SpringUrlShortener/
Assignment #2 Cont
Play around with the site. Make some short URLs*!
You can use the Admin Page to view already created shortened URLs
*Be sure to include a FULL URL path when creating links (http://www.google.com), remember this app is not perfect!!
Assignment #2 Cont
Now let’s add a new feature.
Use vim to open the MainController.java$ vim src/main/java/edu/oakland/shorturl/controller/MainController.java
Add the following code to the file starting at line 46:
@RequestMapping(value="/about", method=RequestMethod.POST)public ModelAndView showABOUTPage() { return new modelandview("ABOUT");
} For this use vim. Refer to the vimtutor slide for a vim refresher
Assignment #2 Cont
Assignment #2 Cont
Time to use git to add this change.$ git add .
This will add the file(s) that we modified to be committed$ git commit -m “My first change”
This will add the changes to the repository
http://git-scm.com/book/en/Git-Basics For help on git.
Assignment #2 Cont
But wait, we are good git users. We should use branches! $ git branch --all
Shows all branches available
Someone already started a branch for this feature. Let’s switch to it$ git checkout new_feature
http://git-scm.com/book/en/Git-Basics For help on git.
Assignment #2 Cont
To view what is different on this branch do this$ git log
Shows the commit history for the particular branch
Looks like someone already completed this feature. Time to merge it back into the master branch
http://git-scm.com/book/en/Git-Basics For help on git.
Assignment #2 Cont
First we need to checkout master$ git checkout master
Switches us back to the master branch
Now let’s merge the other branch into master$ git merge new_feature
Combines the current branch(master) with new_feature.
Assignment #2 Cont
Oh no! We ran into merge conflicts!The MainController.java file has some conflicts that we need to fix.
$ git diffThis will show what has been modified. In this case it will
show the merge conflicts
Assignment #2 Cont<<<<<<< HEAD…=======…>>>>>>> new_feature
The code between HEAD and ====== is the code from the current branch. While the code from ====== to new_feature is from the branch to be merged
Assignment #2 Cont
Depending on your OS, fire up one of the Merge Tools we suggested in the beginning and fix the conflicts!
● MainController.java
If you’re feeling adventurous. Use only vim to fix the conflict!
Assignment #2 Cont
Time to compile and deploy the new feature.
Remember the commands from previous slides to compile and deploy.
Assignment #2 Cont
Compile Errors!
We have compile errors to fix. Time to dust off core utilities to find and fix our errors.
Assignment #2 Cont
Cannot find symbol: class LinkServiceLet’s use find to see if we have a LinkService java file.$ find . -name LinkService.java -type f
The ‘.’ is to search the current directory. ‘-name’ tells find what name we want to look for. ‘-type f’ says we want a file.
We have a file called LinkService at: src/main/java/edu/oakland/shorturl/service/
Assignment #2 Cont
Let’s add the import to get access to the LinkService class.
The package would be edu.oakland.shorturl.service.LinkService
Assignment #2 Cont
The next error is on line 47. Cannot find symbol class modelandview. Let’s use grep to find if modelandview is defined anywhere.$ grep -ri ‘modelandview’ *
Grep does text searching through files. The option ‘r’ tells grep to be recursive. ‘i’ is for case insensitive search.
Assignment #2 Cont
What happens when we do that search again case sensitive?$ grep -r ‘modelandview’ *
We now see that modelandview should be ModelAndView. Let’s change that!
Assignment #2 Cont
Time to compile and deploy the code!
Remember the commands from previous slides to compile and deploy.
Hooray it work!!
Assignment #2 Cont
Would you look at that? We cannot get to the about us page! Method POST not supported.
Use grep to find where the POST method is and change it to a GET.
Assignment #2 Cont
It looks like our developer was sloppy. They forgot to make the admin and about links in the navbar have the class attribute set to active.
Fix this mistake and we are home free!
Assignment #3
Manage webapps using PSI Probe
Follow along in the next few slides to configure Tomcat to use PSI Probe
Assignment #3
$ vim $TOMCAT_HOME/conf/tomcat-users.xml
1. Open tomcat-users.xml in vim (or your favorite text editor)
2. Add a manager-gui role and a username
Assignment #3
<role rolename="manager-gui"/>
<user username="admin" password="s3cr3t" roles="manager-gui"/>
*If you need help with vim, see slide ____, or use your favorite text editor
Assignment #3Psi-Probe can be found at http://localhost:8080/probe
This is the web view, but there is a terminal based script available
Assignment #3
Play around with ProbeIt provides so much more functionality in comparison to the provided tomcat-manager.
Try refreshing / deleting the webapp we just created
Assignment #3
Download and test a PSI Probe script
Hosted by me by digital ocean
If you having trouble executing the shell script, run the following command.
chmod +x webapp_cntl.sh