title: Am I able to run a RESTful Service and angularJS in the same app to avoid CROSS Browser
body: <p>i've done a simple RESTful service using Resteasy and JAXRS in Java. And then i'm trying to call to the service from the "front-end" by using angularJS $http.get.</p>
  
  <p>By the way, using tomcat 7 to run this.</p>
  
  <p>For some reason, with my current web.xml i can't access to the angularJS view with a 404 not found error, but i can access the restful service.</p>
  
  <p>Now, if i add a simple default web.xml, the restful service will no longer work, but the angularJS view will be found.</p>
  
  <p>Can you guys tell me what's wrong? been looking for this for hours.</p>
  
  <p>This is my pom.xml
  </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;angular-js&lt;/groupId&gt;
      &lt;artifactId&gt;angular-js&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;java-version&gt;1.7&lt;/java-version&gt;
      &lt;/properties&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;org.jboss.resteasy&lt;/id&gt;
              &lt;url&gt;http://repository.jboss.org/maven2/&lt;/url&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;jboss&lt;/id&gt;
              &lt;url&gt;http://repository.jboss.org/nexus/content/groups/public-jboss/&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;webXml&gt;src\main\webapp\WEB-INF\web.xml&lt;/webXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.5&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.10&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;2.5&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
              &lt;version&gt;2.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-jackson-provider&lt;/artifactId&gt;
              &lt;version&gt;2.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-jettison-provider&lt;/artifactId&gt;
              &lt;version&gt;2.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-multipart-provider&lt;/artifactId&gt;
              &lt;version&gt;2.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.scannotation&lt;/groupId&gt;
              &lt;artifactId&gt;scannotation&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javassist&lt;/groupId&gt;
              &lt;artifactId&gt;javassist&lt;/artifactId&gt;
              &lt;version&gt;3.12.1.GA&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jettison&lt;/groupId&gt;
              &lt;artifactId&gt;jettison&lt;/artifactId&gt;
              &lt;version&gt;1.3.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
              &lt;artifactId&gt;jsr311-api&lt;/artifactId&gt;
              &lt;version&gt;0.11&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>This is my web.xml
  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
      &lt;display-name&gt;AngularJS Application&lt;/display-name&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;resteasy.scan&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
          &lt;param-value&gt;/&lt;/param-value&gt;
      &lt;/context-param&gt;
  &lt;/web-app&gt;     
  </code></pre>
  
  <p>This is my angularJS code, pretty basic:
  </p>
  
  <pre><code>var teamsApp = angular.module('teamsApp', ['ngRoute']);
  
  teamsApp.config(function($routeProvider) {
      $routeProvider
      .when('/view', {
          controller: 'testCtrl',
          templateUrl: 'partials/view1.htm'
      })
      .otherwise({redirectTo: '/view'});
  });
  
  teamsApp.controller('testCtrl', function($scope, $http) {
      $scope.title = "This is a testing title";
  
      $http({
          url: '/service/getAllPersonsJSON',
          method: "GET",
      }).success(function (data, status) {
              $scope.data = data;
      }).error(function (data, status) {
              $scope.status = status;
      });
  });
  </code></pre>
  
  <p>My index.htm is this one
  </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;html ng-app="teamsApp"&gt;
          &lt;head&gt;
              &lt;title&gt;Testing AngularJS&lt;/title&gt;
              &lt;!-- &lt;link rel="stylesheet" type="text/css" href="style/main.css" media="screen" /&gt; --&gt; 
              &lt;link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" media="screen" /&gt; 
          &lt;/head&gt;
          &lt;body&gt;
              &lt;div class="view-container"&gt;
                  &lt;!-- Place holder for views--&gt;
                  &lt;div ng-view&gt;&lt;/div&gt;
  
              &lt;/div&gt;
  
          &lt;script src="angular/angular.min.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;script src="angular/angular-route.js" type="text/javascript"&gt;&lt;/script&gt;
  
          &lt;script src="scripts/controllers/controllers.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>view1.htm is only a div container with <code>{{title}}</code> value in it.</p>
  
  <p><strong>This is my project structure</strong> <a href="http://puu.sh/5GEuu.png" rel="nofollow">http://puu.sh/5GEuu.png</a></p>
  
  <p>Thanks in advance.</p>