I am new to web application development.
I have been working on developing a rest web service and deploying it locally on apache tomcat server. I am using sts for this.
Now, when I am executing my application from sts (Run as java application). It is running fine. I am hitting the url at localhost:8080 and everything is fine.
Now, I am doing the following :
- Created a .war file for my application, named sample-rest-service.war
- On a different system, I have downloaded and installed tomcat 8 configured to run on port 9999
- I copy my .war file in the webapps folder of apache-tomcat-8.028
- I start my tomcat server using startup.sh
- I type localhost:9999 in my browser and the home page appears
- I type localhost:9999/sample-rest-service, but I get the error message with code 404
- I type localhost:9999/examples and it works fine, i.r. content appears
- I check the webapps folder, .war file has been extracted both war file and the extracted folder are present there.
What am I missing ?
Normally if I run my application through sts, I do this :
- Run as Java Application
- Then it asks me to chose, I chose Application-hello, where Application is the class having main() and hello is the package
- After that in the console I can read the message that Tomcat started on port(s): 8080 (http)
- Now in my browser I type this : http://localhost:8080/greeting
- I get the output in JSON
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_3_1.xsd" version="3.1">
<display-name>sample-rest-service</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
To generate war I did the following :
- Added the maven war plugin in my project
- changed the packaging in pom.xml from jar(default) to war
- Export war file
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<packaging>war</packaging>
</project>
localhost-access.log
say? – Tim Biegeleisen