I have recently been working with Spring Boot and all of the jar dependencies are packaged within the Spring Boot 'uber' jar.
I have recently made a regular jar application and none of the jars are packaged within the jar, but I am still able to execute the code within the java by calling specific classes (with main methods)
Can anyone shed some light? Any similar questions I see regarding this always speak to the shade plugin
EDIT:
I understand I didn't specify the shade plugin to create an uber jar, but could anyone explain why it's not needed for the majority of projects, and how the code is able to run if the dependencies are not there?
Related
I am working on a project, when I run maven test, I get all the dependencies as jars, so I can use methods of classes in those jars when editing the code, however I was wondering when running maven deploy to package the code as a jar and put it on a remote repository, how does this jar execute? doesn't it need all the jars mentioned in the pom? because when reading the contents of the jar it only includes the compiled classes of the code which are under src/main/java.
I think there is a point that I have misunderstood. please if there are some basics that I have missed or I should have known refer me with a good guide.
thanks in advance
It's like you said, to run a jar you need each dependency. But to put it on repository you don't need that.
So basically when you want to create runnable jar you need some maven build plugins which will pack every dependency inside your .jar file like maven-shade-plugin.
If you want to pack a jar to upload it to remote repository for other people to use you don't need that because now it is on the side of someone who will use your dependency to download each dependant jar of your created one (maven does it automatically).
Example
It all depends on what you need to do.
Imagine that you have a console application which shows you weather for Chicago, that application uses dependency for getting weather lets call it weather-dep so your application needs a dependency of weather-dep inside.
And now if you want your user to just run it (jar can be run from console "java -jar yourWeatherApp.jar") you need to package it in a way that yourWeatherApp.jar will have inside weather-dep.jar which maven will download on packaging process.
Second option is when you know that someone want's to show weather in Chicago using yourWeatherApp.jar so that person makes his application lets call it usaWeatherApp.jar and he will include your dependency inside his application he will then be able to use classes from yourWeatherApp.jar but also from weather-dep.jar because it's dependency inside your's app.
You just need to know which use case is best suited for you.
Short answer you package your jar including dependencies when someone wan't to just run your application and not include it's functions/classes etc. inside their app.
I just want to make my jar size smaller. Many of the jars added by maven dependencies are unnecessary, one of them is guava.jar and I am not able to understand its purpose in the project.
What functionality will not work if this jar is removed?
Is there a way to include specific packages during a spring boot application build? I have used spring-boot-maven plugin.
I understand it's not very customary to have classes in the same project which we don't want in the build, but I want to check if this is possible at all?
Even if a spring-boot executable jar can be built using any other way (i.e. by not using the spring-boot-maven plugin) I'd be delighted to know.
My spring boot web app works when run it in eclipse but when I try to run as an executable jar it fails to register any of the beans.
The configuration is all annotated - there are no xml config files.
I used mvn clean compile and mvn package commands to generate the jar.
Has anyone had a similar problem or have any ideas?
Thanks
Executable jars can not include nested jars, so it is necessary to workaround that limitation. A common approach is to shade the jars (i.e. unpacking all jars, and then packing in to single jar).
Spring-boot takes a different approach that relies on a custom maven repackaging plugin and handling by the Spring Boot Loader module. It generally just works, but per the documentation:
The spring-boot-starter-parent POM includes configuration
to bind the repackage goal. If you are not using the parent POM you
will need to declare this configuration yourself. See the plugin
documentation for details.
More information:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-executable-jar
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar
My guess is that you are are you either not using the spring-boot maven plugin, or are not using the spring-boot parent POM. If that's not the issue, then you will need to post more information.
I have now resolved the problem and the app is working as a standalone jar.
Turns out the project folder structure was wrong - such that most of the app was unreachable!
I can't make Proguard Maven plugin to obfuscate files in a web project. I tried some solutions on Stackoverflow - no luck.
My actual application is Vaadin-based packaged with Maven, but I created a sample demo project https://github.com/taskadapter/projectX for now to illustrate the problem.
My end goal is creating a web application WAR file with all maven modules (e.g. "util") and web app code (e.g. "SomeImportantHiddenClass") obfuscated.
the build fails with:
[proguard] Error: The input doesn't contain any classes. Did you
specify the proper '-injars' options?
I saw http://maksim.sorokin.dk/it/2010/08/23/obfuscating-several-jars-in-one-single-maven-build-with-proguard/, but this does not make sense to me.
if I run proguard plugin on every maven module in my project separately, then how will other modules in the same project find required classes if they are all "messed up"?
I assume I need to add proguard execution to either root pom.xml or my web module, which actually packages stuff into a WAR file (see the project on GitHub).
"injar" option allows adding Jars to the obfuscation process, but I expected the plugin to find my modules and obfuscate them without me hardcoding "injar" values like "../util/target/util.jar".
plus proguard documentation does not say anything about "injars" option, it only describes "injar" configuration parameter. neither of them works in this case.
I also saw Proguard is saying it can't find any classes , but I'm not sure moving all the classes from "web" maven module to a separate one is the right solution and not sure it'll work anyway. I'll keep trying...