Tomcat does not unpack spring boot application - java

thank you for your attention in reading my problem;
I'm trying to deploy a spring boot application but when I put it in the tomcat webapps folder it doesn't load my application, does anyone know what could be happening?
I already tried to run several versions of java changing the system variables, I used several versions of tomcat but none unzip the application
I'm using java version 17
and version apache-tomcat-9.0.71
Log Tomcat
Tomcat Past

I thought Spring Boot came with a pre-installed web server, so there is no need to use this method. Why don't you use the current method which supports auto deployment of your application?

An Spring Boot application is a ready to run jar file which contains tomcat/jetty and can be run with java -jar <your app>.jar.
When you want to run an application in tomcat you should build a .war file.
======================================
As found here: https://stackoverflow.com/a/27905557/2144466
Did you follow this guide: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.traditional-deployment
and do you have a class which extends SpringBootServletInitializer andd overwrites the configure method:
`
#SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
`

Please follow below.
Rename your war file at location webapps from web-0.0.1-SNAPSHOT.war to web.war
restart tomcat.
open url (http://localhost:8080/web) in browser.

I managed to solve the problem.
Apparently it was version incompatibility between spring, tomcat and java, by adjusting the system variables I can deploy both java 11 and java 17 applications.
Even though I managed to find a solution, I thank the friends above for dedicating their time to trying to solve my problem.

Related

Hello. Ihave war packaging spring boot soap webservice, i deploy to tomcat but soapui request return error

I have one spring boot jar packaging helloworld soap web service and it works as jar project. But I need war file, i convert it to war packaging project and then deploy to tomcat, but when i test with soapui request return error. This is my test project link:
https://drive.google.com/open?id=1ChKcOxeOGkFpGpjYUh3FabdUFFueRWCw
I want ask, if someone have spring boot soap web service that works correctly?
i use eclipse maven project, tomcat 8.5.23 and soapui, jdk 1.8
this is some part of error text
:
HTTP Status 404 – Not Found HTTP Status 404 – Not Found /codenotfound/ws/helloworldDescription The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.Apache Tomcat/8.5.23
Add "SpringBootServletInitializer" as shown in following code to your main file. Because without SpringBootServletInitializer Tomcat will consider it as normal application it will not consider as Spring boot application
#SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication .class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
}

Spark rest api server deploy

With this link, I made rest api server. It works well when I run on eclipse ide. However, I don't know how to deploy on server. I made war file and tried to deploy on tomcat, but somehow cannot access any page that I defined, unlike running on eclipse. Here is some gradle configuration that I made.
apply plugin: 'war'
war {
baseName = 'server'
manifest {
attributes 'Implementation-Title': 'SparkAPIServer', 'Implementation-Version': '1.0', 'Main-Class': 'com.server.Main'
}
}
I'm sure that 'Main-Class' path is correct. Any idea of this?
Running from Eclipse IDE is not the same like running on Tomcat, because when running on Eclipse Spark uses the built-in Jetty server, and when deployed to Tomcat Spark runs on Tomcat server.
Quoting from the documentation:
Other web server
To run Spark on a web server (instead of the embedded jetty server),
an implementation of the interface spark.servlet.SparkApplication is
needed. You have to initialize the routes in the init() method, and
the following filter has to be configured in your web.xml:
...
So in order to run the same code after deployed to Tomcat, you need to:
Your class should implement SparkApplication.
Implement the init() method, and register all your routes there. (Of course, if you want to be able to run both locally on Eclipse and remotely on Tomcat, just register all your routes to some private method startSpark() which will be called both from init() and from main()).
Your web.xml should be set accordingly.
Seeing that you use Spark and a main method to start a webserver, you are looking actually to create a jar, like the following (adapt as needed):
jar {
manifest {
attributes 'Main-Class': 'com.foo.bar.MainClass'
}
}
See the jar task documentation. And don't forget to add the classpath for your external libraries into the manifest.

What is the difference between spring cloud config server exec.jar and .jar suffix

We are currently using spring cloud config server spring-cloud-config-server-1.1.0.M2-exec.jar and would like to upgrade to the latest version. However, i've noticed that beyond 1.1.0.M2 version there's only standard jars and no exec.jar in Maven repo http://maven.springframework.org/milestone/org/springframework/cloud/spring-cloud-config-server/
Could someone please explain what the difference is? Will I be able to just substitute the exec one with the standard non exec one?
Thanks
The exec jar contains an executable version of the config server (as a Spring Boot application). The non-exec jar contains only the config server classes. So you can't just replace the exec jar with the other one. What you basically have to do is to create a basic Spring Boot application with the config server dependencies and the appropriate annotations (like in the example):
#SpringBootApplication
#EnableDiscoveryClient
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

How to convert jar file to war and deploy it in tomcat server

I am working on dropwizard-maven project.How can we convert the jar file to war file and deploy it in tomcat server.If anyone knows,kindly help.
You cannot just simply convert a jar file to a war file. A Web archive has a structure to be followed and there is no straight forward way to convert the type.
What you can do is, create a web application, import the jar file as dependency and make endpoints in the webapp to trigger calls in the jar you have.
You might need to take a look into why you are using dropwizard, if you are planning to deploy it in a tomcat server.
You might find the below link helpful.
https://github.com/twilio/wiztowar
Add maven war plugin in your pom.xml and run command clean install to generate war file.
You should try wizard in a box, it will let you deploy a Dropwizard application to a Tomcat container as a war.
In the case of a Spring project, Add this to pom.xml.
<packaging>war</packaging>
Not related to drop wizard, but if you are having a Spring boot project and you came here from google, this is what you should do.
Change the packaging to WAR
<packaging>war</packaging>
Mark the tomcat embedded server as provided
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> <!-- This is important. -->
</dependency>
Make your #SpringBootApplication extend SpringBootServletInitializer
#SpringBootApplication
public class HelloWorldApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(HelloWorldApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class);
}
}
I have a detailed article about Converting Jar to War

How to deploy a jar to glassfish, which contains a main method?

I'm new to EJB. I have an ejb-jar file which contains, "Class1" and i deployed it to glassfish server. Now there is another jar file which contains only the following client file(it has a dependencey injection), so my problem is how should i execute this file?
I just deployed it to glassfish, but it doesn't work and show error in log file("it contains zero ejb").
import com.pack.Class1;
public class CreateAccoutnClient {
#EJB
private static Class1 class1;
public
static void main(String[] args) {
}
}
If anyone who have read EJB 3 in Action, i'm tring to deploy chapter3 code to glassfish with eclipse.
Thanks :)
EJB context doesn't execute any main methods, with Glassfish (and others) you must deploy a war to have entry points that run your app or methods (web services or web app).
A jar can contain MDB, remote ejbs or scheduled timers, or could be just a library. The only way to execute some initialization method at startup is to use the EJB3 #Startup annotation

Categories

Resources