I am provided with fat JAR's. Now I want to build a spring boot REST webservice for each. The webservice needs to use the classes and libraries in the fat JAR. Unfortunately the JAR'S in the lib folder of the fat JAR are not used by either maven or the IDE out of the box.
The only working solution I found so far is to unzip the fat JAR and then add the libs folder to my project.
How do I use the fat JAR with my spring boot webservice?
First what are the dates jars?do they contain spring annotations? You could create a spring boot project as a wrapper and write your own rest controllers to interface with the fat jars. It's hard to provide you more direction without understanding what the fat jars are
Related
How can I tell maven to include dependency jar files while building a fat jar, rather than unpacking them to .class files?
I have a vertx 3.6.0 project producing a fat jar. I am using vertx-maven-plugin:1.0.13, and I run mvn clean package to build. In order to take advantage of Veracode SCM (static scanning), the dependencies inside my fat jar have to be intact, meaning the original dependency jar files have to be contained inside my fat jar. Maven is unpacking all dependencies though, so all I have are class files.
We have another spring boot project which works as expected. It seems the final spring boot repackage goal puts all the dependency jar files in the BOOT-INF dir inside the jar file.
Final 2 goals using vertx-maven-plugin:
maven-jar-plugin:2.4:jar
vertx-maven-plugin:1.0.13:package
Final 2 goals using spring-boot-maven-plugin:
maven-jar-plugin:2.4:jar
spring-boot-maven-plugin:2.1.2.RELEASE:repackage
I've searched the docs for vertx-maven-plugin and all over https://maven.apache.org and elsewhere without any luck so far.
Is there a way to get this same repackage behavior for a non spring boot app?
You can't do that with Vert.x because it doesn't do fancy classloading.
But since it's embeddable, you can create a SpringBoot app that just starts Vert.x. Then you'll get your dependency scanner working.
But I would first check with Veracode if it' can't inspect your POM or Gradle build file instead of scanning a JAR.
If your packaging requirement is for the veracode scan piece, you would probably try packaging your project artifacts into a tar, or zip using the maven-assembly plugin.
Veracode couldn't scan a dependency jar inside another jar for a non-spring boot project. So, you can try one of the following. i) tar packaging using maven-assembler plugin, or ii) convert it to spring-boot project if thats simpler and you could ,or iii) uber-jar creation using maven-shade plugin and need to make some configuration changes for not getting unpackaged to .class files. Still would suggest you can explore with the tar packaging option - (reference:) https://maven.apache.org/plugins/maven-assembly-plugin/
I am creating fat jar for my maven project and my project has many claases dependency. Actually, it is an apache beam project which I always upload to google data flow.
I am writing some codes and everytime I want to debug and test the code I shoud uplaod a 200MB fat jar to the server, Can I just make my fat jar for just one classes in my project?
I have a java application and a Spring Boot application. I want to MySpringBootApp.run() and MySpringBootApp.hereYouHaveSomeInfo(), so I want to call methods of the Spring Boot App but Spring Boot kind of processes my class and renames it, so I get a ClassNotFoundException in the other App.
Thanks for you help!
If I understand you correctly, you are building the executable version of the spring boot application.
This jar file cannot be used as a dependency.
You need to build the classical jar file without the dependencies and add this to your application's dependency list.
I suppose you build with maven. The target folder will contain two files:
a yourapp-<version>.jar and
a yourapp-<version>.jar.original which is substanially smaller.
The .jar File is not suitable for inclusion as a dependency. You need the .original file. I suggest, if you need both, that you setup a project creating the .original file as regular .jar target, without the spring-boot plugin. And you add another project, with the spring-boot plugin, that requires the "simple" .jar file as dependency and has the spring-boot plugin enabled.
Your second application will also list the "simple" jar file as a dependency, the fat jar can be delivered as usual.
Why after building spring boot app, it generates two jar or war files with .original extension? I use spring boot maven build plugin.
For example:
application.jar
application.jar.original
The answer is that you are using repackage goal in your spring-boot-maven-plugin.
So, What it does?
Maven first builds your project and packages your classes and resources into a WAR (${artifactId}.war) file.
Then, repackaging happens. In this goal, all the dependencies mentioned in the pom.xml are packaged inside a new WAR (${artifactId}.war) and the previously generated war is renamed to ${artifactId}.war.original.
I assume that you're using the spring boot maven build plugin. This behavior is documented here: https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
I currently have a project built with maven-archetype-webapp artifact. The default packaging for this project is war.
Is it possible for me to insert the maven-ear-plugin in this webapp pom.xml generate an ear file that contains this project war? I tried that, but the war file doesn't get embedded in the generated ear file. It has everything except the war file.
I read many Maven related articles, and perhaps I could use maven-archetype-j2ee-simple artifact. However, I'm reluctant to this use for 2 reasons:-
This artifact handles ejbs and all the extra features that I don't use. It makes my project looks bloated.
Second, it seems like it requires me to install the web module into the repository first before I can create the ear file. Is this the preferred way to create an ear file?
How do I create an ear file that contains the war file using maven-ear-plugin from my webapp's pom.xml? If this way is not possible, what's the preferred way?
I'm sorry if my questions sound a little novice, I realized I have whole lot more to learn about Maven.
Thanks much.
The maven ear plugin assumes that any WAR is a separate project, so you need two projects, plus a parent project. It's a function of how maven does packaging. Each project produces one artifact. There are ways around this, but Maven will punish you for your sins. This question goes into some detail on this topic.