I have a pretty straight forward servlet running in Tomcat, which roughly starts like this
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import security.AuthenticationFilter;
@ApplicationPath("/")
public class MyMain extends ResourceConfig {
private final static Logger logger = LoggerFactory.getLogger(MyMain.class);
private Map<String,Map<String,String>> myConfig = null;
public MyMain() {
final String myEnv = System.getProperty("myEnvironment");
// doing more stuff, registering resources ...
}
}
The project runs locally in my Eclipse, which also starts and stops Tomcat. There is a Server beside my project.
But the server (Tomcat) does not start the servlet
I have checked my server and deploy path against the run configuration in Eclipse and they should match.
The pom.xml looks like this:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sustainableDataPlatform.org</groupId>
<artifactId>my-project</artifactId>
<!-- <version>0.1.1</version>-->
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>MY PROJECT</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jersey>2.32</version.jersey>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<!-- https://stackoverflow.com/a/33390519/2092322 annotations instead of web.xml -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<warName>my-project</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20151123</version>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>4.2.0</version>
</dependency>
<!-- maybe use jakarta mail? javax.mail 1.4.x? -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.4.1</version>
</dependency>
</dependencies>
</project>
Server Configuration in Eclipse and its results
# server.xml in tmp folder after starting the server (*run on server*)
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Context docBase="/home/myname/work/sdp/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/ROOT" path="" reloadable="false"/>
<Context docBase="sdp-api" path="/sdp-api" reloadable="true" source="org.eclipse.jst.jee.server:sdp-api"></Context>
</Host>
# same part of server.xml in Server folder of server project in Eclipse after having the servlet project configured for (added to) server
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Context docBase="sdp-api" path="/sdp-api" reloadable="true" source="org.eclipse.jst.jee.server:sdp-api"/>
</Host>
Targeted Runtime of the servlet project: Tomcat
while I do not get 'Runtime Composition'. What is that?
Project Build path
And what is still confusing me is the order part of the build path config, maybe I am doing something wrong here.
Old
I have adjusted the execution environment and ideally the server has a reference to the servlet project, not the other way round
Now, when I export the project in Eclipse, I am getting a fine my-project.war. But when I run mvn clean package
the server throws errors and when I try to start it again, Eclipse yells at me:
Publishing failed with multiple errors
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF.
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF.
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/maven/mainPackage/my-project/pom.properties.
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/maven/mainPackage/my-project/pom.properties.
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/maven/mainPackage/my-project/pom.xml.
File not found: /path/to/my-project/target/m2e-wtp/web-resources/META-INF/maven/mainPackage/my-project/pom.xml.
So I need to:
- decouple the project from the Tomcat Server
- When I just run it again on the Server, the servlet is not running, so I need to bind the project back to the Server in Eclipse by using the reference:
This changes .classpath
:
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-11-oracle">
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
and
- <attribute name="owner.project.facets" value="java"/>
+ <attribute name="maven.pomderived" value="true"/>*
First question: what does this mean?
.project
is of course also changed:
<projects>
+ <project>Servers</project>
</projects>
I am pretty sure that I have a wrong configuration somewhere and I would like to use mvn
besides Eclipse. But what exactly am I doing wrong?
Any more config stuff needed?