Spring application with embedded jetty can't find webdefault.xml if running from jar

前端 未结 6 529
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 15:19

I have spring application which uses embedded Jetty instance.

project
   | src
      | controller
      | webapps
          | jsp
          | WEB-INF
                    


        
6条回答
  •  灰色年华
    2021-02-03 15:47

    From @Trein's post, setting the WAR_LOCATION is important. I have seen jetty failing to deploy the web app when this is missing.

    Assuming that you are using Jetty to test your app, if you are using Maven POM below is how I test my web app

    pom.xml

     
                org.springframework
                spring-test
                ${spring.version}
                test
            
    
            
                org.mortbay.jetty
                jetty-servlet-tester
                6.1.22
                test
            
            
                org.mortbay.jetty
                maven-jetty-plugin
                6.1.19
                test
            
        
    
    
        
            
                tomcat
     
            
                        
                            org.mortbay.jetty
                            maven-jetty-plugin
                            6.1.22
                            
                                10
                                foo
                                9999
                                /
                                src/main/webapp
                                
                                    
                                        RESOURCE_PATH
                                        ${project.build.outputDirectory}
                                    
                                
                                
                                    
                                        9090
                                        60000
                                    
                                
                            
                            
                                
                                    test-compile
                                    
                                        run
                                    
                                    
                                        0
                                        true
                                    
                                
                                
                                    stop-jetty
                                    package
                                    
                                        stop
                                    
                                
                            
                        
                    
                
            
    
    

    To run the webapp you can either run mvn jetty:start or run mvn package. This starts the Jetty server on port 9090 and runs the tests (run your http based tests here) and shutdown the server/webapp. If you want to run as standalone webapp, use mvn jetty:start and use your webapp just like any webapp container.

    This all assumes you are using Maven. The code above provided by @Trein does the same programatically and the one I provided is the maven configuration equivalent of the above.

    Note: You shouldn't worry about webdefault.xml as the default is already packaged in the jetty jar file. You should use your own webdefault.xml only when you need to extend/alter the defaults. There is either something wrong with your Jetty jar (if its reporting this or something to do with your CLASSPATH settings)

提交回复
热议问题