How to create/find application jar to deploy your spring boot maven application using embedded tomcat? - spring

I want to deploy my application using the embedded tomcat in spring -boot. I figured that I have to run the java -jar spring-boot-app.jar command, but I cannot find the jar file for the application anywhere.
On running mvn clean package I am able to generate a war file to deploy externally, how can I do the same with embedded tomcat ?

You need to remove following line from pom.xml
<packaging>war</packaging>
or replace war packaging with jar. Make sure you have spring-boot-maven-plugin in maven build plugins
The jar should then be available in target folder

To create an executable jar, we need to add the spring-boot-maven-plugin to our pom.xml. To do so, insert the following lines just below the dependencies section:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
For more information,refer this :
https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html

Related

Deploy a jar to a wildfly server?

I want to deploy an application packaged in a jar to a wildfly server after maven package phase, and before maven install.
I am using the following plugin in the project pom.xml:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.1.0.Beta1</version>
<configuration>
<hostname>127.0.0.1</hostname>
<port>9990</port>
</configuration>
</plugin>
how to configure this plugin execution?
You need the deploy goal of that plugin. It accepts a filename parameter which you could use to specify the application archive that you want to deploy.
Binding this goal to the deploy phase of Maven will not override other goals being invoked in that phase of the Maven lifecycle. They will continue to run.

Springboot executable jar error using java -jar

using command /opt/jdk1.8.0_211/bin/java -jar webprx.jar get this error: Error: Invalid or corrupt jarfile webprx.jar
jar was build with mvn clean package and mvn install
Pom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
Remove the executable configuration.
From the documentation this makes it executable by *NIX systems.
Make a fully executable jar for *nix machines by prepending a launch script to the jar.
Currently, some tools do not accept this format so you may not always
be able to use this technique. For example, jar -xf may silently fail
to extract a jar or war that has been made fully-executable. It is
recommended that you only enable this option if you intend to execute
it directly, rather than running it with java -jar or deploying it to
a servlet container.
https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/maven-plugin/repackage-mojo.html

How to prevent lombok from being packaged into Spring Boot jar?

If you visit official Lombok Maven guide, you will see that it's scope should be provided.
When I create a new project from scratch using start.spring.io and add Lombok, it gets only <optional>true</optional> in resulting pom.
Then I package Spring boot app like this and out of curiosity decide to see what gets packaged inside of jar:
mvn clean package -DskipTests=true && unzip target/demo-0.0.1-SNAPSHOT.jar -d exploded
Lombok is packaged, does not matter if I set scope to provided or only have optional=true.
How to prevent Lombok from being included to Spring Boot jar?
My last thought was to try another goal which comes with Spring Boot plugin:
mvn spring-boot:repackage
But unfortunately it produces the following error:
repackage failed: Source file must be provided
Lombok will only be available in a seperate folder lib-provided instead of the usual lib folder if you are packaging war file.
In order to exclude lombok completely from the final jar/war file, you have to do this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.1.RELEASE</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
Please refer to Exclude a dependancy section of Spring Boot Maven Plugin https://docs.spring.io/spring-boot/docs/2.3.x/maven-plugin/reference/html/#repackage-example-exclude-dependency for more details.
Looks like it's a transitive dependency of one of your dependency. If you confirm it, you know what to do.

Maven Jetty plugin configure repository

We use jetty plugin for local deployment of our application. Recently i added a repository in the pom and added dependencies both in the plugin section and the dependencies section outside as well, when i build the war and deploy it on standalone app server everything works ok, however the same application when i try to run through the jetty application it throws me error for that particular dependency.
Is there any way that we can configure the external repositories to be used by the plugins in order to resolve the dependencies.
Thanks,
- Vaibhav
If I understand your issue right, you can add a dependency to the jetty-maven-plugin itself and have it available to your application. Something like this:
<plugin>
<groupId>org.eclipse.jetty.maven</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.14.v20161028</version>
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
</plugin>

Run two maven modules using mvn tomcat7:run

I've got the following project layout:
web_root
- pom.xml -> packaging: pom
- web_relay
- pom.xml -> packaging: war
- src/...
- web_service
- pom.xml -> packaging: war
- src/...
My web_root's pom.xml has is the superproject and contains two modules: web_relay and web_service.
For reasons unknown someone split these projects rather arbitrarily. I've been trying to merge these projects under one maven superproject.
I can run each of the web_relay and web_service projects using mvn tomcat7:run. However, I need both running on the same tomcat server. When I run tomcat7:run on web_root, however, it only runs the tomcat server for one of the two modules.
How can I get mvn tomcat7:run to run both wars?
The approach from How to use maven plugin tomcat7:run with multiple contexts (WARs)? works only if I mvn install my dependencies separately and don't include them as modules. If I do include them as modules, mvn will just run tomcat7:run in the first module it finds.
Run the war's from a dummy module, listing all dependencies as 'webapps'.
I.e. in the individual pom's, use:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
And make a new module that launches all dependencies at once
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<webapps>
<webapp>
<groupId>com.company</groupId>
<artifactId>webapp-1</artifactId>
<version>1.0</version>
<type>war</type>
</webapp>
[Add more]
</webapps>
As an alternative, and maybe a better solution in the long run, package all web applications in a single EAR (enterprise archive: https://maven.apache.org/plugins/maven-ear-plugin/), so you can also deploy them in production in a single action.
Tomcat7 does not support EAR deploys, but TomEE does: http://tomee.apache.org/maven/run-mojo.html
And JBoss, too: https://docs.jboss.org/jbossas/7/plugins/maven/latest/run-mojo.html

Resources