I am trying to utilize an existing Spring Boot application that is hosted on my company's Maven repository. This application takes messages from a Kafka server and puts them in a Mongo database. All that is needed to make it work is supply it with a properties file that defines the Kafka and Mongo servers. I need to create a Maven project that imports this application as a dependency, and supplies it with a properties file for the configuration. The only two files should be a pom.xml and application.properties. The end result should be a runnable JAR that executes the dependency (the existing Spring Boot application) using my properties file.
I do not have a choice in taking a different approach in solving this.
I have spent countless hours trying to configure Maven to do this. I had finally succeeded in getting this to work when using the mvn spring-boot:run
command, but I cannot get it to produce a properly working runnable JAR file.
I include my dependency like any other:
<dependencies>
<dependency>
<groupId>com.company.dept</groupId>
<artifactId>consume-to-mongo-app</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Then, I define the main class from the dependency like this:
<properties>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
</properties>
And, my plugins section looks like this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Application runs fine when running mvn spring-boot:run
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
After running mvn clean package
, then java -jar myjar.jar
I get thousands of these:
)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: java.lang.reflect.InvocationTargetException
... 1024 more