Files
Latest commit
JavaScript
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||
This directory contains example of using HTML+JavaScript with REST API. Available Files: ----------------- HTML and JavaScript files are available in: assignment7/src/main/webapp/ 1) ajaxexample.html Once you build and deploy the application in Eclipse, you can access this file to study how a HTML+JavaScript code can interact with REST API using the Asynchronous JavaScript (AJAX) technology. You can access this file at: http://localhost:<port>/<context-root>/ajaxexample.html This html file contains JavaScript code which makes AJAX call to the REST API, which is available at: http://localhost:<port>/<context-root>/assignment7/helloworld/helloworld where the <context-root> is "/" 2) ajaxexample-snapshot.html This HTML file is similar to ajaxexample.html with the only difference that the <context-root> for the REST API is "assignment7-0.0.1-SNAPSHOT". The reason why the context root is different in this case is explained below. Using mvn to build the project: ---------------------------------- You can use mvn commands to build the project. - Compile: mvn clean compile - Create war: mvn package war:war For war file generated by using mvn commands the context root is: <artifactId>-<version> from pom.xml In our case: - artifactId is "assignment7" - version is "0.0.1-SNAPSHOT" Therefore, the context root is: assignment7-0.0.1-SNAPSHOT The reason you need to understand these steps is explained below. Deploying webapp to Tomcat on Cloud VM: ---------------------------------------- Till now we have used an IDE (Eclipse, Intellij) for deploying our webapps. But for assignment7 we will be deploying our webapp on Tomcat on a Cloud VM. We won't have access to Eclipse on a Cloud VM, but we will have to build the '.war' file using mvn commands outlined above. Steps for deploying a webapp to Cloud VM: ------------------------------------------- 1) Sign up for a cloud provider 2) Create cloud server: E.g.: <Ubuntu 14.04, Standard flavor> on Rackspace (https://developer.rackspace.com/signup/) 3) Login 4) Install required software and packages - apt-get update - Install Tomcat - apt-get install tomcat7 (This will install tomcat in /var/lib/tomcat7) - Start Tomcat ./var/lib/tomcat7/bin/startup.sh - Find IP address of your VM - Via control panel - Via command line (ifconfig and eth0) - Access tomcat - curl <IP-address>:8080 5) Generate war file - Install git: apt-get install git - Use git to clone your code from bitbucket/github - Install maven: apt-get install maven - Install open-jdk-7: apt-get install openjdk-7-jdk - Compile: mvn clean compile - Create war: mvn package war:war - Copy assignment7-0.0.1-SNAPSHOT.war to /var/lib/tomcat7/webapps/ 6) Tomcat related: - Logs are available at: /var/lib/tomcat7/logs/catalina.out - Check the logs using: tail –f catalina.out - Tomcat server port can be modified as follows: - In /var/lib/tomcat7/conf/server.xml - change Connector element’s port attribute - Stop Tomcat: ./var/lib/tomcat7/bin/shutdown.sh - Start Tomcat: ./var/lib/tomcat7/bin/startup.sh 7) Access application at: http://<IP-address>:8080/assignment7-0.0.1-SNAPSHOT/assignment7/helloworld/helloworld