CS281: Advanced Programming Configuration Information: How to: -‐ install eclipse -‐ install maven -‐ configure java 1.6 jdk -‐ install tomcat
-‐ create and deploy a simple html web application -‐ create and deploy a simple servlet web application -‐ create and deploy a simple wicket web application
INSTALLING ECLIPSE
-‐ Download Eclipse IDE for Java EE Developers at: http://www.eclipse.org/downloads/
-‐ Place the “eclipse” folder in a location that you have access to on your computer. -‐ Create a desktop shortcut to the eclipse executable in the eclipse folder.
-‐ Start eclipse.
INSTALLING MAVEN
-‐ Goto Help-‐>Install New Software
-‐ In the “Work With” drop down select “Juno” -‐ In the filter text box type “Maven”
-‐ Click Next
-‐ Click Next
-‐ Accept the terms of license agreement
-‐ Wait for Installing Software process to complete -‐ Restart eclipse
-‐ You’ll see an “Updating Index” process run for a while
INSTALLING THE JAVA SDK
-‐ You need the Java 1.6 SDK, located here:
http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-‐ 1902814.html
MAKE SURE THAT THE VERSION YOU DOWNLOAD IS USING JAVA 1.6 NOT JAVA 1.7
-‐ For OS X things are trickier… if you have Mountain Lion, Apple will force you to upgrade to Java 1.7, but you can circumvent the upgrade by reading this: http://support.apple.com/kb/HT5559
INSTALLING TOMCAT
-‐ goto: http://tomcat.apache.org/download-‐70.cgi -‐ Download either the zip file (os x) or (Windows) -‐ Unzip the file into a folder in your home directory -‐ For OS X:
o Create a file called “start_tomcat” in your home directory with these contents:
#!/bin/sh
export CATALINA_HOME=~/apache-‐tomcat-‐7.0.34 $CATALINA_HOME/bin/startup.sh
o Create a file called “stop_tomcat” in your home directory with these contents:
#!/bin/sh
export CATALINA_HOME=~/apache-‐tomcat-‐7.0.34 $CATALINA_HOME/bin/shutdown.sh
o Open a terminal window, type “cd” to go to the home directory, and type this command:
chmod a+x startup_tomcat.sh chmod a+x stop_tomcat.sh
o From the terminal window, run startup_tomcat.sh like this:
./startup_tomcat.sh
-‐ For Windows:
o Add the following environment variables (see this link for how to in Windows 7: http://www.itechtalk.com/thread3595.html):
CATALINA_HOME = c:\Users\<youruserid>\apache-‐tomcat-‐7.0.34 JAVA_JRE = c:\Program Files\Java\jre6
o Create a shortcut to startup.bat and shutdown.bat on your desktop. You’ll find these batch files in %CATALINA_HOME%\bin. Make sure that the “Start In” directory is set to %CATALINA_HOME%\bin.
o Click on the startup.bat shortcut
-‐ Test Tomcat by opening a browser and typing the following URL:
http://localhost:8080
-‐ You should see this:
-‐ Set up permissions so that you can deploy applications from Eclipse to Tomcat. Edit the $CATALINA_HOME/conf/tomcat-‐users.xml file and add the following line
immediately after the xml element (choose appropriate password) <tomcat-‐users>:
. . .
<tomcat-users>
<user username="admin" password="xxxxx" roles="manager-gui,manager-script"/> .
.
-‐ Test the permissions by going to the following url: http://localhost:8080/manager -‐ Enter userid “admin” and password “xxxxx” (whatever the password was you
specified).
-‐ You should see this:
CREATING AND DEPLOYING A WEB PAGE:
-‐ startup Eclipse, and do File-‐>New-‐>Other-‐>Maven Project -‐ Next
-‐ Click on the “Configure” button next to the filter box:
-‐
-‐ Click on “Add Remote Catalog”
-‐ Enter: http://204.144.14.136:10000/nexus-‐2.3.0-‐04/content/repositories/releases/ in the first text box
-‐ Enter: CS281 Maven Archetypes in the second text box
-‐ Click OK to dismiss the “Remote Archetype Catalog” -‐ Click OK to dismiss the “Archetypes”
-‐ Use the Catalog dropown to select CS281 Maven Archetypes -‐ Select “webhtml-‐archetype”
-‐ Press “Next”
-‐ Fill in:
o Group id: cs.stonehill.edu o Artifact id: WebHelloWorld
-‐ Click “Finish”
-‐ If you have problems and you are using Windows… then try this. o Download this file and put it in your .m2 directory:
http://www.stonehill.edu/compsci/CS281/settings.xml
o Edit the file and change the <localrepository> content element to be absolute location of your .m2 directory
o Create a “releases” folder in your.m2 directory o Windows-‐>Preferences-‐>Maven-‐>User Settings o Click on the update settings button
o Try to load the maven archetype again
-‐ Now open the WebHelloWorld project using the Eclipse Project Explorer. Drill down to the index.html file:
-‐ Change the HTML file so that it says “Hello <yourname>!” NOTE: Any html, image, or other resource files should be placed in the webapp directory if they are to be
correctly deployed to the web server.
-‐ Modify the following plugin code in the pom.xml file set the username to “admin” and the password to the correct password for your tomcat installation.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/text</url>
<username>admin</username>
<password>xxxxx</password>
</configuration>
<version>1.1</version>
</plugin>
-‐ Save the pom.xml file.
-‐ Now you are ready to deploy the web application to the tomcat webserver. -‐ Right-‐click on the project WebHelloWorld in the project explorer, Run As -‐> Run
-‐ Click on the the Maven_Build option, then press the New Configuration button (upper right corner of the dialog box):
-‐ In the Maven Build Configuration Dialog set: o Name: WebHelloWorld
o Goals: tomcat:redeploy o Press “Apply” then “Run”
-‐ You should see a console window appear with lots of feedback involving the deploy. If the deploy goes successfully, then you’ll see this in the console window:
-‐ Test out your web application by typing the following URL: http://local:8080/WebHelloWorld
-‐ You should see this:
HOW TO CREATE AND DEPLOY A BASIC SERVLET
SEE APPENDIX: CONFIGURING ECLOPSE, WINDOWS, and SERVLETS if you have a windows machine.
-‐ startup Eclipse, and do File-‐>New-‐>Other-‐>Maven Project -‐ Select the CS281 catalog and the “servlet-‐archetype” -‐ Enter “ServletHelloWorld” for the artifact id
-‐ Goto the project’s pom.xml file and enter the correct url, username, and password for your tomcat installation (SEE CREATING AND DEPLOYING WEB PAGES for details) -‐ Right click on the project, Run As -‐> Run Configuration
-‐ Select “Maven Build” and create a new maven build for the project
-‐ Run the build you’ve created (SEE CREATING AND DEPLOYING WEB PAGES for details)
-‐ If your deploy was successful, then you should see this when you type the servlet’s url in the web browser:
HOW TO CREATE AND DEPLOY A WICKET APPLICATION
-‐ startup Eclipse, and do File-‐>New-‐>Other-‐>Maven Project -‐ Select the CS281 catalog and the “wicket-‐archetype” -‐ Enter “WicketHelloWorld” for the artifact id
-‐ Goto the project’s pom.xml file and enter the correct url, username, and password for your tomcat installation (SEE CREATING AND DEPLOYING WEB PAGES for details) -‐ Right click on the project, Run As -‐> Run Configuration
-‐ Select “Maven Build” and create a new maven build for the project
-‐ Run the build you’ve created (SEE CREATING AND DEPLOYING WEB PAGES for details)
-‐ If your deploy was successful, then you should see this when you type the servlet’s url in the web browser:
HOW TO DEPLOY TO THE DEPARTMENT SERVER
You can access the department server like this:
ssh <yourusername>@204.144.14.136
use the password xxxxx
You should be able to start the tomcat web server immediately by entering the
following command:
./start_tomcat
You should be able to stop the tomcat web server by entering the following
command:
./stop_tomcat
You should be able to access the tomcat web server using the following url:
http://204.144.14.144:xxxxx
where xxxxx is:
bdugan -‐> 8080
jmcbrine -‐> 11080
kbhatt -‐> 12080
kboates -‐> 13080
llange -‐> 14080
mplummer -‐> 15080
roshea -‐> 16080
ssifferlen -‐> 17080
To deploy to the department server (and your tomcat server running on the
server) you will use the following plugin in your project pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://204.144.14.144:8080/manager/text</url> <username>xxxxx</username> <password>xxxxxx</password> </configuration> <version>1.1</version> </plugin>
WANT TO CREATE YOUR OWN ARCHETYPES?
Read about this here:
http://johnjianfang.blogspot.com/2009/05/create-‐maven-‐archetype-‐from-‐existing.htm
APPENDIX: CONFIGURING ECLIPSE, WINDOWS, and SERVETS
1) Install the Java SE 1.6 JDK using this URL:
http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-‐ 1902814.html
2) Start up eclipse again
3) Goto Windows-‐>Preferences-‐>Java-‐>Installed JREs 4) Click “Add”
5) Click “Directory” and select the directory for the Java 1.6 SDK For me this was located at: C:\Program Files\Java\jdk1.6.0_39
6) Now select the Java 1.6 JDK jre as the default jre for eclipse: 7) Click “OK”
8) You won’t have to do steps 1-‐8 anymore… yeah!
9) Create a maven servlet-‐archetype project from the CS281 archetypes. There are FIVE problems you have to correct to get your project working:
-‐ incorrect build path
-‐ missing resources directory
-‐ incorrect name for main java program
-‐ tomcat admin userid/password need to be set -‐ incorrect JRE selected for maven build
10)To correct the build path, right click on the “JRE System Library” and select properties. Select the “Workspace default JRE” radio button and click OK:
11)To correct the missing resources directory, expand the src folder, right click on the main folder, select New-‐>Folder, name the folder “resources”, press Finish:
14) To correct the file naming problem, expand the java folder, right click the file “ServletHelloWorld.java” , select rename, set the new name of the file to the artifactId that you provided when you created the maven project. In this example, my
artifactId was ServletTestII, then press OK.
12)At this point you should not have any errors in your project and it should look something like this:
The last thing you have to do is set the correct tomcat deployment url,, userid, password in the project’s pom.xml file.
13)To correct the incorrect JRE for the maven build do the following:. Assuming that you’ve set a run configuration for servlet builds:
-‐ Run-‐>Run Configurations. -‐ select the servlet build -‐ click on the JRE tab
-‐ make sure that the “WORKSPACE DEFAULT JRE” is checked -‐ click APPLY -‐ click RUN