I want to create a war file from a Spring application for download, which I can deploy to a standalone Tomcat container without using the built-in.
I can create a war file and run it myself using "java -jar pdfjs-annotator.war" and it works fine.
I built the application using gradle bootRepackage (using Gradle, Tomcat7, Java 1.7).
But when I deploy the war file to a stand-alone Tomcat and run it, the application seems to load without errors according to the log, but I canβt access any resources and work with the controller URLs.
For example, my index.html is a static html page in src / main / resources / static / index.html, which I usually call through localhost: 8080 / index.html, but when deployed to stand-alone Tomcat, the page is not delivered (it then in the military file in WEB-INF / classes / static / index.html) via the same URL. And also any display of the controller does not work. Instead, I get a 404 error.
build.gradle:
buildscript { ext { springBootVersion = '1.2.3.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE") } } apply plugin: 'java' apply plugin: 'eclipse-wtp' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'war' war { baseName = 'pdfjs-annotator' version = '1.0.0-SNAPSHOT' } allprojects { apply plugin: 'java' sourceCompatibility = 1.6 targetCompatibility = 1.6 } repositories { mavenCentral() } configurations { providedRuntime } dependencies { compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-data-rest") compile("org.springframework.boot:spring-boot-starter-web") runtime("mysql:mysql-connector-java") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") testCompile("org.springframework.boot:spring-boot-starter-test") compile ('org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final') } eclipse { classpath { containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER') containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7' } } task wrapper(type: Wrapper) { gradleVersion = '2.3' }
My main application :
@EnableJpaRepositories @SpringBootApplication public class PdfAnnotator extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(PdfAnnotator.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(PdfAnnotator.class); } }
When I look at the blown up war, I see the following META-INF / MANIFEST.MF :
Manifest-Version: 1.0 Start-Class: com.mypackage.pdfcomment.PdfAnnotator Spring-Boot-Version: 1.2.3.RELEASE Main-Class: org.springframework.boot.loader.WarLauncher
The gradle build process usually generates two military artifacts: one named .war and one named .war.original -.war is the one that contains the corresponding MANIFEST.MF entries, and the one I used to deploy the stand-alone Tomcat.
What is missing? I already checked here for other SO questions here:
as well as Spring Boot documents, but could not find a hint of what's wrong.
* === Update === *
I installed the new Tomcat7, deployed a war file there and everything worked fine. It seemed that I had a problem with the instance / configuration of Tomcat. Not sure what the problem is, but I will not worry about it, because now it works fine with the new Tomcat.