JavaScript-Example
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: js-example/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>/app/path/helloworld-resource Note: When deploying this app in Eclipse, change the 'context-root' to '/' The default context root of 'js-example' will not work as ajaxexample.html makes calls to the REST API that is assumed to be running with context-root of '/'. 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 Deploying webapp to Tomcat on Cloud VM: ---------------------------------------- Till now we have used an IDE (Eclipse, Intellij) for deploying our webapps. But for js 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 js-example.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 REST API at: http://<IP-address>:8080/js-example/app/path/helloworld-resource/ 8) Access HTML pages at: http://<IP-address>:8080/js-example/ajaxexample.html