Spring boot project, build and package a jar file then upload it to the server, run it:
java -jar xxx.jar
How can I make it auto reload when I upload a new jar file?
add Spring Boot DevTools to your dependencies for developer friendly options like auto restart of the server:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
Related
I would like to use the Spring Initializr to create WAR for tomcat...
Our DevOps are still not used to the idea of running java as a standalone and would like to have the application as a WAR in tomcat
I was able to produce a project but it seems like its producing a standalone spring boot application
I still want to use Spring Initializr to produce all the dependencies like :
Rest Repositories
JDBC template
Quartz
REST
One solution is to create a dynamic web project in eclipse and use Spring Initializr then just copy all the pom dependency into the dynamic web project
is there a better way?
To build a deployable war file into an external container, you have to :
Reconfigure your project to produce a WAR
Declare the embedded container ( Tomcat ) dependency as provided
<packaging>war</packaging>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>
Using spring boot war build during the start up of the application in the tomcat
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/scheduling/quartz/SpringBeanJobFactory.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
even though it exists as a dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
And also spring-context-support
There are no issues with spring boot jar build and run
How to fix the issue for the war deployment?
This is what I get when debugging jar file - maybe this might help: (with war file ClassNotFoundException)
I'm not sure, it's just suggestion:
Try to add dependencies:
<!--Quartz-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
NOTE: It's just a way to 'hot fix'. And it is not a complete solution.
Figured out the issue. As I was running Tomcat from the IntelliJ Idea and new dependencies introduced to the project were not reflected. Needed to remove and reimport war/war exploded into Tomcat configuration - no issues.
Try to add the following dependency (if you want you can set Spring version by yourself):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
If we run sprin-boot:run in linux
where will be the tomcat running path.
what will the folder structure of tomcat for jar and war.
will there be any work or webApps folder created?
How to find the tomcat path in linux,will it be running as separate tomcat service or the java application service.
suppose any hot fix deployment with jsp change, which was possible if there is a webapps, is it possible with spring boot?
You deploy Spring Boot as an executable JAR and run it using java -jar. It's the main class that is executed.
Tomcat or Jetty is the HTTP listener; it's running inside Spring Boot. It's the reverse of creating a WAR and deploying it to Tomcat.
There's no work or web apps folder created.
Embedded Servers in Spring boot
The idea of Embedded Server is to make the server part of the application,so in this case to be able to deploy directly to the virtual machine,you only need to have virtual machine with java already installed.
for using embedded service using tomcat you will need to have this conf in pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.0.0.RELEASE</version>
<scope>compile</scope>
</dependency>
starter-tomcat itself also has these dependecies :
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>
Which are the tomcat dependency enough to run your application as a single jar on it's own.
Summary
in spring boot when we create an application deployable, we would embed the server inside the deployable (for example tomcat). this means, you can generate an application jar which contains Embedded Tomcat. You can run a web application as a normal Java application.as a result, When you execute mvn spring:boot run it's exactly equivalent as executing java -jar command but maven also make sure about some suble considrations:
your application are given the right parameters
making sure your application already compiled
More Info
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html
I downloaded from github http://websystique.com/spring-boot/spring-boot-angularjs-spring-data-jpa-crud-app-example/ and import as maven and I cannot add this app to tomcat.
If i changed packaging from jar to war, I can add, but get 404 on localhost:8080/SpringBootCRUDApp
How can i run this app?
You do not need to add it to tomcat. Spring Boot uses a public static void main entry-point that launches an embedded web server for you. So just run main method.
In Your Application, you already added Springboot-starter-web Dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
And packaged your application as "jar" as below in pom.xml
<packaging>jar</packaging>
"spring -boot-starter-web" dependency has inbuilt embedded Tomcat container, so you don't need to add anything in Tomcat container
You can run your application with below command in cmd
java -jar SpringBootCRUDApplicationExample.jar
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
use this example for your reference.
I created a small java application using intellij, later I updated that project as Maven project using "Add framework support" option. When I tired to add spring jar file on project I got following error saying,"No files were downloaded for org.springframework:org.springframework.core:3.2.2.RELEASE".
Following are the steps I did to add spring jar files
1)Clicked on File -> Project Structure -> Modules -> Clicked on "+" Sign -> Library -> From Maven
2)Searched for org.springframework.core and selected 3.2.2 Release
3)Downloaded to lib folder under my project.
4)Got Error.
I don't know where it went wrong. I am new to java and spring application.
As already mentioned, Maven downloads dependencies itself (a reason why it's a build automation tool).
To add Spring as a dependency, add this code to Maven's pom.xml (the file is in your module's root directory):
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
</dependencies>
Also, delete the lib directory from your project root - Maven doesn't put jars there.
Maven downloads the dependencies automatically, can you try adding this to the pom.xml file. Maven should automatically download the dependencies..
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>