using spring-boot-maven-plugin with exec classifier, but can't run the app from IDE anymore - maven

I am working on Spring Boot 1.5.9 application, and I am generating a jar that contains a Spring Boot application, but that can also be imported as part of another project.
Therefore, I am using below config to generate 2 jars : the exec, and the regular lib ones.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
However, now that I have this, I am not able to run the application from my IDE (Intellij) anymore, as it's not finding the application.yml.
I am sure there's a trick, but I can't find anything.. Any idea ?

I ended up using Maven profiles :
<profiles>
<profile>
<id>makeRelease</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I make the release, I am calling this profile (maven with argument -P makeRelease) so that it generates the 2 jars.
The rest of the time, the regular behavior applies.

Related

Spring Boot 2.2.1 Create two jar's while Build [duplicate]

This question already has answers here:
Why spring boot generates jar or war file with .original extension?
(2 answers)
Closed 3 years ago.
I am working on Spring boot version 2.2.1.RELEASE.While building my project two jar's will created having types executable jar file and original file as given below
The reason for this is
Maven first builds my project and packages my classes and
resources into a jar (${artifactId}.jar) file.
Then, repackaging happens. In this goal, all the dependencies
mentioned in the pom.xml are packaged inside a new WAR
(${artifactId}.jar) and the previously generated war is renamed to
${artifactId}.jar.original.
Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.data.MainService</mainClass>
</configuration>
</plugin>
</plugins>
</build>
How can we avoid to create ORIGINAL File type jar file.
Is there any disable /excluding technique available in maven.
Am also tried following <build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.data.MainService</mainClass>
</configuration>
</plugin>
</plugins>
</build>
As per the implementation jar.original is expected. Nothing to worry about.
Re packaging creates new jar file and renames old one to jar.original
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins.html#build-tool-plugins-repackage-implementation

tomcat8-maven-plugin ? (emphasis on the 8!)

Is there a version 8 (tomcat8) of the below?
<build>
<finalName>SampleServletFinalName</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
and corresponding
mvn tomcat7:run
maven search does not reveal anything
https://search.maven.org/classic/#search%7Cga%7C1%7Cg%3A%22org.apache.tomcat.maven%22
Unfortunately, the plugin is not yet ready but you can find some workarounds here :
Tomcat 8 Maven Plugin for Java 8
Maybe the tomee-maven-plugin solves your problem as well:
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>7.1.1</version>
</plugin>
The difference here is, that you wont get a Tomcat, but TomEE. You can compare them by looking at this matrix.
(Version 7.1.1 wraps a Tomcat 8.5.41)

Deploy Java EE Wildfly REST Application to Openshift

I am new to Openshift and having trouble with deploying my Java EE project to it. I have made REST API for a simple webstore. Locally it works fine on Wildfly 9.0.2 I want to deploy it on openshift. I 've made new wildfly9 + mysql5.5 application using eclipse openshit jboss plugin and added a profile to root pom.xml:
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>webstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
My root project consist of several maven modules including store-ear (EAR), store-jpa (JAR), store-rest (WAR), store-web (WAR), store-services (EJB), store-rest-interfaces (JAR),store-service-interfaces (JAR).
I have changed datasourse in JPA configuration (persistence.xml) to use MysqlDB on Openshift.
After pushing back to openshift the build is succesfull, but when it gets deployed it is missing some dependancies (ClassNotFoundException), and fails to deploy main war file.
You use a maven-war plugin in your openshift maven profile.
But you say that your project is packaged as en ear. So you should probably deploy this ear which contains all your project modules (wars, ejbs, libs...) instead of a specific war of your project.
To achieve this, you have to use a maven-ear plugin instead of the maven-war one in your openshift profile which would look like this:
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

How to deploy Spring Boot application to different URL on Tomcat?

I am building and deploying my Spring Boot application into Tomcat with mvn tomcat:deploy and with this configuration:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>tomcat</server>
<path>/${project.build.finalName}</path>
<username>admin</username>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
Application runs then at /${project.artifactId}. I would like to deploy the application to the another URL, ideally to set target URL while I call Maven deploy command. Is it possible? If so, how can I achieve it?
You can override maven properties from command line with -D option.
To specify another url for your app the interesting properties are maven.tomcat.port and maven.tomcat.path.
The following command line should do the trick :
mvn -Dmaven.tomcat.port=8181 -Dmaven.tomcat.path=/custom tomcat:deploy

Intellij 13.1.2 not unpacking exploded (sub-) artifacts

With Intellij < 13.1.2 we were able to locally have a exploded artifact with exploded subartifacts for development, the actual version 13.1.2 is putting out *.jar and *.war files instead of directories.
I found this workaround in their bugtracker: http://youtrack.jetbrains.com/issue/IDEA-124353
but was wondering how to achieve this for all modules, instead of having to list all of them?
Ok, I found my workaround by adding a maven profile for intellij and enabling it:
<profiles>
<profile>
<id>intellij</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<unpackTypes>war,ejb</unpackTypes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Resources