I have a Jersey 2 Maven project.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>com.api.rest.ApplicationResource</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>com.api.rest.ApplicationResource</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.api</groupId>
<artifactId>GLI_API</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>GLI_API</name>
<build>
<finalName>GLI_API</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>com.cloudinary</groupId>
<artifactId>cloudinary-http44</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.19</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
My project works fine when working locally. But it doesn't work anymore when i deploy it on my remote server.
So what happens is basically, that the WAR gets deployed correctly but there is really no error or warning in catalina.out. I get a 404 on every of my defined endpoints.
catalina.out:
Sep 14, 2015 2:03:00 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/GLI_API.war
Sep 14, 2015 2:04:17 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/ICDS_API.war
Sep 14, 2015 2:04:23 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
Sep 14, 2015 2:04:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 14, 2015 2:04:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 84867 ms
ApplicationResource:
package com.api.rest;
import java.util.logging.Logger;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import com.api.provider.ResponseCorsFilter;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
public class ApplicationResource extends ResourceConfig {
private static final Logger LOGGER = null;
public ApplicationResource() {
// Register resources and providers using package-scanning.
packages("com.api");
System.out.println("started");
register(MultiPartFeature.class);
// Register my custom provider - not needed if it's in my.package.
register(ResponseCorsFilter.class);
// Register an instance of LoggingFilter.
register(new LoggingFilter(LOGGER, true));
// Enable Tracing support.
property(ServerProperties.TRACING, "ALL");
}
}
What could be the problem? I developed on tomcat8 (but don't remember using something specifically) and deployed on tomcat7. Could this be a problem?
This endpoint should be reachable: http://54.228.220.152:8080/GLI_API/api/item
The other API works fine - so the server in general is working.
Also - if you don't have the final answer i would really appreciate it if you can point me to files/directories to look at since i don't get any error.
You may try to enable annotation scanning by setting this init parameter to your servlet:
<servlet>
...
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.yourproject.packageWhereYourResourcesAre</param-value>
</init-param>
...
</servlet>
Update
It seems you have compiled against Java 8, while Tomcat runs with Java 7? Try this:
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
You may also want to update your web.xml to 3.0:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
Related
I followed a REST API | Web service tutorial on the web and got stuck midway. When I run the server it setups successfully, shows that its running at http://localhost:8080/ as well but as soon as I try to access different servlets, the page reloads and returns with 404 Error Not found. I tried downloading earlier versions of wildfly with no avail. The paths I tried were /demorest, /webapi, /myresources and they were used in conjunction as well.
What could be the problem?
package com.david.demorest;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("myresource")
public class MyResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.david.demorest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.david</groupId>
<artifactId>demorest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demorest</name>
<build>
<finalName>demorest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>3.0.4</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
It's likely that the tutorial is written to deploy to Tomcat. Wildfly has everything you need for JaxRS built in.
To get started you will need three files. First, you need a class that extends javax.ws.rs.core.Application. It can be in any package you'd like:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/rest")
public class RestApplicationConfig extends Application {
// intentionally empty
}
Next, you need your service. The one you show should work though I'd have my Path start with a forward slash like #Path("/myresource"). Lastly, you need a pom.xml that produces a war file. I haven't tested yours but I have one that looks like:
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jaxrs-simple-sample</artifactId>
<groupId>com.hotjoe.jaxrs</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
That I just verified works. Once you have all of this you can produce a war file that can be dropped into $WILDFLY_HOME/standalone/deployments and Wildfly will run it. But you need to watch the URL. As defined in my pom.xml this will create a war file named jaxrs-simple-sample-1.0-SNAPSHOT.war and this file name becomes part of the URL. In this example, the URL to your service would be http://localhost:8080/jaxrs-simple-sample-1.0-SNAPSHOT/rest/myresource. The rest part of that comes from the #ApplicationPath defined. But the other part comes from the name of the war. If you don't like that, you can add one more Wildfly specific file:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>myapp</context-root>
</jboss-web>
This file, in a standard Maven environment, would be named jboss-web.xml and would be placed in src/main/webapp/WEB-INF. This would change the above URL to http://localhost:8080/myapp/rest/myresource.
I demonstrate asynchronous process in REST API using javax(2.26 version). When I tried I got"A filter or servlet of the current chain does not support asynchronous operations." I don't know what to do with that. I tried many ways but doesn't work out.
The below is the resource file
Resource.java
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.MediaType;
import com.jersey.rest.User;
#Path("/async")
public class AsynDemo {
#POST
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_JSON)
public void asyncMethod(#Suspended final AsyncResponse response, User user) {
new Thread() {
public void run() {
response.resume(true);
}
}.start();
}
}
Pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jersey</groupId>
<artifactId>rest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>rest</name>
<build>
<finalName>rest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- uncomment this to get JSON support-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.security</groupId>
<artifactId>oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.10.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.26-b03</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Client checking java file
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import com.jersey.rest.User;
public class MainTesting {
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:9090/rest/jwt/async");
AsyncInvoker invoker = target.request().async();
Future<Boolean> response = invoker.post(Entity.entity(new User(), MediaType.APPLICATION_JSON), Boolean.class);
try {
System.out.println(response.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
APPLICATION ERROR
SEVERE: Servlet.service() for servlet [Jersey jwt Application] in context with path [/rest] threw exception [java.lang.UnsupportedOperationException: Asynchronous processing not supported on Servlet 2.x container.] with root cause
java.lang.UnsupportedOperationException: Asynchronous processing not supported on Servlet 2.x container.
at org.glassfish.jersey.servlet.WebComponent$3.suspend(WebComponent.java:137)
at org.glassfish.jersey.servlet.internal.ResponseWriter.suspend(ResponseWriter.java:125)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.suspend(ServerRuntime.java:921)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:326)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:337)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at..................```
Tomcat exception
```WARNING: Unable to start async because the following classes in the processing chain do not support async [org.glassfish.jersey.servlet.ServletContainer]
java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
at org.apache.catalina.connector.Request.startAsync(Request.java:1692)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1050)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.getAsyncContext(AsyncContextDelegateProviderImpl.java:112)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.suspend(AsyncContextDelegateProviderImpl.java:96)
at org.glassfish.jersey.servlet.internal.ResponseWriter.suspend(ResponseWriter.java:125)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.suspend(ServerRuntime.java:921)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:326)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:337)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Err....
Aug 21, 2020 5:07:24 PM org.glassfish.jersey.servlet.internal.ResponseWriter suspend
WARNING: Attempt to put servlet request into asynchronous mode has failed. Please check your servlet configuration - all Servlet instances and Servlet filters involved in the request processing must explicitly declare support for asynchronous request processing.
java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
at org.apache.catalina.connector.Request.startAsync(Request.java:1692)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1050)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.getAsyncContext(AsyncContextDelegateProviderImpl.java:112)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.suspend(AsyncContextDelegateProviderImpl.java:96)
at org.glassfish.jersey.servlet.internal.ResponseWriter.suspend(ResponseWriter.java:125)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.suspend(ServerRuntime.java:921)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:326)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.Serv.....
Aug 21, 2020 5:07:24 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey jwt Application] in context with path [/rest] threw exception [javax.ws.rs.ProcessingException: Attempt to suspend a connection of an asynchronous request failed in the underlying container.] with root cause
javax.ws.rs.ProcessingException: Attempt to suspend a connection of an asynchronous request failed in the underlying container.
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:327)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:337)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
....```
Could you help me to solve this? :)
Add <async-supported>true</async-supported> in web.xml servlet definition.
<servlet>
<servlet-name>Jersey jwt Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.jersey.jwt</param-value>
</init-param>
<async-supported>true</async-supported>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey jwt Application</servlet-name>
<url-pattern>/jwt/*</url-pattern>
</servlet-mapping>
it solved the issue.
I m building a web app and using apache poi for working on excel sheets. When I start the server I get the following exception. Thing is it used to work fine until i tried to build it and deploy in on heroku (but might be irrelevant).
Anybody has an idea??
INFO: Starting service Catalina
Apr 15, 2016 8:28:35 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Apr 15, 2016 8:28:36 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.engine.OnStartup
java.lang.NoClassDefFoundError: org/apache/poi/EncryptedDocumentException
at org.engine.OnStartup.contextInitialized(OnStartup.java:16)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.EncryptedDocumentException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 10 more
My pom.xml file:
<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>psilos-toy</groupId>
<artifactId>psilos-toy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.httpcache4j.resolvers</groupId>
<artifactId>resolvers-net-urlconnection</artifactId>
<version>4.0-M6</version>
</dependency>
<!-- Apache POI,for handling Excel Files -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
<!-- jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
and my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.endpoints</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.engine.OnStartup</listener-class>
</listener>
</web-app>
Perhaps it was working on a Tomcat setup that had poi classes available on the classpath. In the new Heroku setup, perhaps you don't have those classes available with Tomcat 7 (I haven't thoroughly checked if poi classes come bundled with Tomcat 7).
The easiest thing you can do is to build a self-contained app by bundling the poi classes along with your app. This increase your app's size, but you get to control the poi library version. Of course, you can always copy the libraries to a defined folders (where you know Tomcat loads the classes from). See maven-shade-plugin for details.
I have build a web appliation containing a Spring MVC project with a mysql database and a tomcat7 server. This is now published to GIT of OpenShift.
But starting the server takes only 160ms and I can clearly see nothing is being loaded really.
How do I do a real deployment and connect the Openshift Tomcat to my project?
I can code, but deployment-wise I am not a smart bulb.
My GIT repository looks like this:
What is wrong?
EDIT:
As requested the pom.xml:
<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>com.afterguard</groupId>
<artifactId>SailPlanner</artifactId>
<version>0.8.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>sailplanner</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.openshift</groupId>
<artifactId>openshift-java-client</artifactId>
<version>2.7.0.Final</version>
</dependency>
</dependencies>
</project>
The web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>SailPlanner</display-name>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>sailplanner</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sailplanner</servlet-name>
<!-- <url-pattern>/</url-pattern> -->
<url-pattern>/index</url-pattern>
<url-pattern>/inside/admin</url-pattern>
<url-pattern>/inside/admin/save</url-pattern>
<url-pattern>/inside/admin/delete</url-pattern>
<url-pattern>/inside/calendar_race</url-pattern>
<url-pattern>/inside/calendar_cruise</url-pattern>
<url-pattern>/inside/blog</url-pattern>
<url-pattern>/inside/blog/submit</url-pattern>
<url-pattern>/inside/blog/delete</url-pattern>
<url-pattern>/inside/event_feed</url-pattern>
<url-pattern>/inside/event/create</url-pattern>
<url-pattern>/inside/event/delete</url-pattern>
<url-pattern>/inside/event/crew/add</url-pattern>
<url-pattern>/inside/event/crew/remove</url-pattern>
<url-pattern>/inside/event/save</url-pattern>
<url-pattern>/login</url-pattern>
<url-pattern>/logout</url-pattern>
<url-pattern>/403</url-pattern>
<url-pattern>/registration</url-pattern>
<url-pattern>/inside/yacht/create</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/sailplanner-servlet.xml,
/WEB-INF/spring-security.xml,
/WEB-INF/spring-database.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Git Push Log (of successful build):
Repository ssh://566ffc920c1e668c8a000049#afterguard-sailplanner.rhcloud.com/~/git/afterguard.git/
Stopping jbossews cartridge
Sending SIGTERM to jboss:333213 ...
Stopping MySQL 5.5 cartridge
Stopping PHPMyAdmin cartridge
Waiting for stop to finish
Waiting for stop to finish
Repairing links for 1 deployments
Building git ref 'master', commit 277c797
Using Maven mirror /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo//.openshift/config/settings.rhcloud.xml
Apache Maven 3.0.4 (r1232336; 2012-12-18 14:36:37-0500)
Maven home: /usr/share/java/apache-maven-3.0.4
Java version: 1.7.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-573.12.1.el6.x86_64", arch: "i386", family: "unix"
Found pom.xml... attempting to build with 'mvn --global-settings /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo//.openshift/config/settings.rhcloud.xml clean package -Popenshift -DskipTests'
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SailPlanner 0.8.0
[INFO] ------------------------------------------------------------------------
Downloading: http://maven.repository.redhat.com/techpreview/all/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.pom
...A LOT OF BUILDING AND DOWNLOADING...
Downloaded: http://mirror.ops.rhcloud.com/nexus/content/groups/public/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar (422 KB at 6105.7 KB/sec)
[INFO] Packaging webapp
[INFO] Assembling webapp [SailPlanner] in [/var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/target/sailplanner]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/WebContent]
[INFO] Webapp assembled in [517 msecs]
[INFO] Building war: /var/lib/openshift/566ffc920c1e668c8a000049/app-root/runtime/repo/WebContent/ROOT.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.062s
[INFO] Finished at: Tue Dec 22 05:35:45 EST 2015
[INFO] Final Memory: 16M/161M
[INFO] ------------------------------------------------------------------------
Preparing build for deployment
Deployment id is 0f103f85
Activating deployment
Starting MySQL 5.5 cartridge
Starting PHPMyAdmin cartridge
Starting jbossews cartridge
Found 127.3.145.129:8080 listening port
-------------------------
Git Post-Receive Result: success
Activation status: success
Deployment completed with status: success
Tomcat log of OpenShift:
Dec 22, 2015 6:47:27 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1503 ms
Dec 22, 2015 6:47:27 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 22, 2015 6:47:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Dec 22, 2015 6:47:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.3.145.129-8080"]
Dec 22, 2015 6:47:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 251 ms
File Structure of ROOT.WAR, which is located in /var/lib/openshift/<uuid>/app-root/runtime/repo/WebContent :
|- META-INF
|- resources
|-- css
|-- fonts
|-- img
|-- js
|- WEB-INF
|-- classes
|--- com
|---- ...
|-- jsp
|--- index.jsp
|--- more jsp-sites
|-- jspf
|--- JSPF SITES I USE
|-- lib
|--- THE LIBS
|-- sailplanner-servlet.xml
|-- spring-datasource.xml
|-- spring-security.xml
|-- web.xml
It seems that you have forgotten to add an openshift maven profile inside your pom.xml like bellow with proper maven-war-plugin configuration.
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>travel</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Then your application structure seems unusual. Usually to build a WAR with maven you put your webapp content in src/main/webapp, your resources in src/main/resources your WAR specific classes in src/main/java.
Take a look at maven-war-plugin user guide here.
Finally, check these documentations that could help you to unterstand how to deploy your application to Tomcat with OpenShift:
Host and Run Your Java Tomcat Application for Free on OpenShift’s PaaS
Tomcat Application Hosting
If you follow properly steps described in these documentations, then any git push will trigger a build and application re-deployment to Tomcat
EDIT
As you have a build compilation issue now (Java 8 not supported), you should take a look at this answer: invalid target release 1.8
I have a JSP application on OpenShift Tomcat.
But all of my source code located in /src/main
Java src code in /src/main/java that means com.example.Main 's location is <APP_NAME>/src/main/java/com/example/Main.java
JSP src code in /src/main/webapp that means index.jsp 's location is <APP_NAME>/src/main/webapp/index.jsp
Have you actually performed a git commit and git push?
If so, can you dump the logs from git push.
Starting to learn Spring MVC dynamic web project with Maven and make it support Eclipse IDE with a simple hello world example but running into issues when I try to run on server. I get the below error:
Problem accessing /SampleSpringMaven/. Reason Service Unavailable
Here is my console:
Starting preview server on port 8080
Modules:
SampleSpringMaven (null)
SampleSpringMaven (/SampleSpringMaven)
2014-04-22 11:51:49.441:INFO:oejs.Server:jetty-8.1.10.v20130312
2014-04-22 11:51:49.989:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{null,file:/C:/Users/mlim/Eclipse/Test/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/SampleSpringMaven/},C:/Users/mlim/Eclipse/Test/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/SampleSpringMaven
java.lang.IllegalStateException: Null contextPath
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:686)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:280)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.wst.server.preview.internal.PreviewStarter.run(PreviewStarter.java:72)
at org.eclipse.wst.server.preview.internal.PreviewStarter.main(PreviewStarter.java:29)
2014-04-22 11:51:50.493:INFO:/SampleSpringMaven:Initializing Spring root WebApplicationContext
Apr 22, 2014 11:51:50 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Apr 22, 2014 11:51:50 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Apr 22 11:51:50 EDT 2014]; root of context hierarchy
Apr 22, 2014 11:51:50 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Apr 22, 2014 11:51:51 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#29871db1: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
Apr 22, 2014 11:51:51 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 570 ms
2014-04-22 11:51:51.155:INFO:/SampleSpringMaven:Initializing Spring FrameworkServlet 'mvc-dispatcher'
Apr 22, 2014 11:51:51 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization started
Apr 22, 2014 11:51:51 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Tue Apr 22 11:51:51 EDT 2014]; parent: Root WebApplicationContext
Apr 22, 2014 11:51:51 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Apr 22, 2014 11:51:51 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#11846d13: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#29871db1
Apr 22, 2014 11:51:51 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 459 ms
2014-04-22 11:51:51.727:INFO:oejs.AbstractConnector:Started SelectChannelConnector#0.0.0.0:8080
and web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Sample Spring Maven Project</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
and jsp file:
<html>
<head>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<title>Being Java Guys | Hello World</title>
</head>
<body>
<center>
<h2>Being Java Guys | Hello World</h2>
<h4>${message}</h4>
</center>
</body>
</html>
and pom file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.beingjavaguys.sample</groupId>
<artifactId>SampleSpringMaven</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleSpringMaven Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jdk.version>1.6</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SampleSpringMaven</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>my-tomcat</server>
<path>/SampleSpringMaven</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
thanks in advance
Did you add POM file., at times the repos don't get downloaded properly, you might need to delete the existing repos and Update the maven project to download the dependecies again.
Here is the basic POM you can start with.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.beingjavaguys.sample</groupId>
<artifactId>SampleSpringMaven</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleSpringMaven Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jdk.version>1.6</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SampleSpringMaven</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>my-tomcat</server>
<path>/SampleSpringMaven</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
You could also look into this it has the basic stuff to get started with Spring.
http://www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html