How do I set the path (URL) of a Java web application correctly so there are no 404 (Not Found) errors when the project is in production?

Asked

Viewed 301 times

1

I have a Java web project in which I use the Jersey framework. When I deploy to my localhost (use Tomcat 9) everything works, when I take it to Heroku the app works too. However, when I request a service, for example, on my localhost. I use the url "http://localhost:8080/myapp.service/Rest/person" to save the entity data Pessoa. When I request the app by the url "https://my-app.herokuapp.com/myapp.service/rest/pessoa" me returns error 404. I believe that in the process of deploying with the "Heroku-Maven-plugin", the url is being another.

I use these plugins in pom.xml:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </configuration>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
</plugin>
<plugin>
    <groupId>com.heroku.sdk</groupId>
        <artifactId>heroku-maven-plugin</artifactId>
        <version>2.0.13</version>
</plugin>

My web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    id="WebApp_ID" version="4.0">
    <display-name>myapp</display-name>

    <servlet>
        <servlet-name>Jersey REST Api</servlet-name>
        <servlet-class>
            org.glassfish.jersey.servlet.ServletContainer
        </servlet-class>
            <init-param>
                <param-name>jersey.config.server.provider.packages</param-name>
                <param-value>myapp.app.rest</param-value>
            </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Api</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

This is the log of when I deploy with the mvn clean Heroku:deploy-War command:

[INFO] Scanning for projects...                                                                                                                                         
[INFO]                                                                                                                                                                          
[INFO] ---------------------< doctorplus:doctorplus.app >----------------------                                                                                         
[INFO] Building doctorplus.app 0.0.1-SNAPSHOT                                                                                                                           
[INFO] --------------------------------[ war ]---------------------------------                                                                                             
[INFO]                                                                                                                                                                  
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ doctorplus.app ---                                                                                            
[INFO] Deleting C:\Users\meunome\eclipse-workspace\doctorplus.app\target                                                                                              
[INFO]                                                                                                                                                                  
[INFO] >>> heroku-maven-plugin:2.0.13:deploy-war (default-cli) > package @ doctorplus.app >>>                                                                           
[INFO]                                                                                                                                                                  
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ doctorplus.app ---                                                                                
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                       
[INFO] skip non existing resourceDirectory C:\Users\meunome\eclipse-workspace\doctorplus.app\src\main\resources                                                       
[INFO]                                                                                                                                                                  
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ doctorplus.app ---                                                                                   
[INFO] No sources to compile                                                                                                                                            
[INFO]                                                                                                                                                                  
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ doctorplus.app ---                                                                        
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                       
[INFO] skip non existing resourceDirectory C:\Users\meunome\eclipse-workspace\doctorplus.app\src\test\resources                                                       
[INFO]                                                                                                                                                                  
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ doctorplus.app ---                                                                           
[INFO] No sources to compile                                                                                                                                            
[INFO]                                                                                                                                                                  
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ doctorplus.app ---                                                                                        
[INFO] No tests to run.                                                                                                                                                 
[INFO]                                                                                                                                                                  
[INFO] --- maven-war-plugin:3.2.1:war (default-war) @ doctorplus.app ---                                                                                                
[INFO] Packaging webapp                                                                                                                                                 
[INFO] Assembling webapp [doctorplus.app] in [C:\Users\meunome\eclipse-workspace\doctorplus.app\target\doctorplus.app-0.0.1-SNAPSHOT]                                 
[INFO] Processing war project                                                                                                                                           
[INFO] Copying webapp resources [C:\Users\meunome\eclipse-workspace\doctorplus.app\WebContent]                                                                        
[INFO] Webapp assembled in [1650 msecs]                                                                                                                                 
[INFO] Building war: C:\Users\meunome\eclipse-workspace\doctorplus.app\target\doctorplus.app-0.0.1-SNAPSHOT.war                                                       
[INFO]                                                                                                                                                                  
[INFO] <<< heroku-maven-plugin:2.0.13:deploy-war (default-cli) < package @ doctorplus.app <<<                                                                           
[INFO]                                                                                                                                                                  
[INFO]                                                                                                                                                                  
[INFO] --- heroku-maven-plugin:2.0.13:deploy-war (default-cli) @ doctorplus.app ---                                                                                     
[INFO] Configured Artifact: com.github.jsimone:webapp-runner:8.5.47.2:jar                                                                                               
[INFO] Copying webapp-runner-8.5.47.2.jar to C:\Users\meunome\eclipse-workspace\doctorplus.app\target\dependency\webapp-runner.jar                                    
[INFO] -----> Packaging application...                                                                                                                                  
[INFO]        - app: doctorplus-app                                                                                                                                     
[INFO]        - including: target/dependency/webapp-runner.jar                                                                                                          
[INFO]        - including: target/doctorplus.app-0.0.1-SNAPSHOT.war                                                                                                     
[INFO] -----> Creating build...                                                                                                                                         
[INFO]        - file: target/heroku/build.tgz                                                                                                                           
[INFO]        - size: 32MB                                                                                                                                              
[INFO] -----> Uploading build...                                                                                                                                        
[INFO]        - success                                                                                                                                                 
[INFO] -----> Deploying...                                                                                                                                              
[INFO] remote:                                                                                                                                                          
[INFO] remote: -----> heroku-maven-plugin app detected                                                                                                                  
[INFO] remote: -----> Installing JDK 1.8... done                                                                                                                        
[INFO] remote: -----> Discovering process types                                                                                                                         
[INFO] remote:        Procfile declares types -> web                                                                                                                    
[INFO] remote:                                                                                                                                                          
[INFO] remote: -----> Compressing...                                                                                                                                    
[INFO] remote:        Done: 83.5M                                                                                                                                       
[INFO] remote: -----> Launching...                                                                                                                                      
[INFO] remote:        Released v17                                                                                                                                      
[INFO] remote:        https://doctorplus-app.herokuapp.com/ deployed to Heroku                                                                                          
[INFO] remote:                                                                                                                                                          
[INFO] -----> Done                                                                                                                                                      
[INFO] ------------------------------------------------------------------------                                                                                         
[INFO] BUILD SUCCESS                                                                                                                                                    
[INFO] ------------------------------------------------------------------------                                                                                         
[INFO] Total time:  05:34 min                                                                                                                                           
[INFO] Finished at: 2019-11-10T12:20:42-03:00                                                                                                                           
[INFO] ------------------------------------------------------------------------  
  • If you can, log Heroku when deploying

  • I edited the question and put the log. Apparently everything ok!

  • Log the Heroku console, it is easier to identify the problem

  • Hello, Have you set your context? Once Tomcat is used, set the context according to the apache documentation Context definition in WAR projects is not defined in the Java EE specification, so each server has its own more information here Hugs!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.