Using echache 2.7.5, I tried
mvn -Dmaven.test.skip=true package
but it makes many jars:
./terracotta/bootstrap/target/ehcache-terracotta-bootstrap-2.7.5.jar
./management-ehcache/target/management-ehcache-2.7.5.jar
./ehcache-core/target/ehcache-core-2.7.5.jar
./ehcache-core/target/classes/net/sf/ehcache/pool/sizeof/sizeof-agent.jar
./ehcache-scheduled-refresh/target/ehcache-scheduled-refresh-2.7.5.jar
./ehcache/target/ehcache-2.7.5.jar
./management-ehcache-impl/ehcache-rest-agent/target/ehcache-rest-agent-2.7.5.jar
./management-ehcache-impl/ehcache-rest-agent/target/original-ehcache-rest-agent-2.7.5.jar
./management-ehcache-impl/management-ehcache-impl/target/management-ehcache-impl-2.7.5.jar
and
./ehcache/target/ehcache-2.7.5.jar
doesn't contain any class files.
How do I target a single jar?
The Ehcache build uses a profile to build its shaded jar. The profile is named fullmode and needs to be activated: -Pfullmode.
The default is devmode which does not do the shading but instead produces pom files with proper transitive dependencies. The logic behind that is faster build times for devs who want to test changes of internal components and not have to rebuild the full jar each time.
Related
I'm building a project where the final war/jar size is very big. I am not sure how to reduce the size of the jar.
How to build only the jars required for the project?
Currently we just given maven build plugin in the dependencies and artifact id on the top which builds the war or jar
Please advise.
Thanks.
use dependency:analyze on your project to analyze used and unused dependencies, so you can exclude unwilling dependency files, i search a lot for a plugin to do it automatically, but I get disappointed in it. if you find please inform me.
https://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html
JAR files typically don't include dependencies, so unless you're building a so-called fat JAR, they should never get very big.
For WAR files:
Remove unneeded dependencies from your POM.
Optionally, move static assets (images etc.) to a web server instead of including them in your application.
If you have dependencies that are being used by multiple applications, include them on the application server level instead of inside your WAR file.
You can use the combination of two mvn commands:
1] mvn dependency:tree -> to understand the entire structure of jars in your project
2] mvn dependency:analyze -> as mentioned above to understand used and unused dependencies
after that you can start removing unused dependencies and always make sure to do mvn clean install and run your project locally to see if there are dependency issues.
I'm looking for a way to create an executable jar file for my JavaFX application.
I'm currently using the zenjava maven plugin and I use the jfx:jar goal. Doing this, all the dependencies are generated on a folder called /lib.
The problem arises when one of the dependencies (a separate project handled by another group) is updated, I would need to rebuild my jar again.
Is it possible to just maybe refer to the dependencies using a pom? (not point to the lib) So I would only update the pom every time a dependency is updated?
Thanks in advance!
Short answer: nope, not possible
Long answer: the JavaFX-Maven-Plugin is usable for development (via mvn jfx:run) and deployment (via mvn jfx:jar or mvn jfx:native).
You are generating a potential deployable package, which already contains everything needed to execute on some targeted machine. You would have to encapsulate your javafx-application with a "pre-loader" which downloads all your required stuff to be executable.
What is the idea behind distributing an application which needs some internet-connection to gather all the required dependencies?
Disclaimer: I'm the maintainer of the javafx-maven-plugin.
I have a project that generates some classes and resources that should then be packaged into a jar.
The class that does the generating has several dependencies. The generated classes have no dependencies.
My initial solution was to use the maven assembly plugin to only include the generated files. Unfortunately, the packaged pom includes all the dependencies required to do the generation. Consumers of this jar pull in a bunch of unnecessary dependencies.
I looked into the maven shade plugin. I compile once, run the generator class with mojo's exec plugin, the compile a final time. Then shade of course runs in the package phase. It creates a dependency-reduced-pom.xml without the excessive dependencies. So run mvn clean package and look in target/foo.jar. I expect the jar in the meta-inf folder to be the reduced dependency jar. But it's the full pom. I don't know how have the generated pom replace the one that is packaged.
Another poor solution I tried was using multiple profiles with their own dependency section. I run maven once with the generating profile, then again with the packaging profile. This works, but sucks because you have to run multiple maven commands. It's not jenkins friendly.
Am I going about this the wrong way? How should I go about arranging a project that generates some code and some text files that are then packaged in a maven friendly artifact?
1) One possibility is to make all your dependencies <optional>true</optional>.
The pom will still have the dependencies but the projects using your library won't try to download them.
2) Use plugin dependencies with the exec plugin.
That works well if the generator class is defined on another project.
Ideally you would call your generator using a plugin and avoid adding those dependencies to your project. That may not be worth doing depending on what your project is for and how reusable your generator has to be.
3) If you are using maven-shade-plugin the dependency-reduced-pom.xml is normally used. Check your .m2 repository to see the contents of the pom that is copied there when you do mvn install. It's likely that its contents will match the dependency-reduced-pom.xml
I'm hacking on a Maven-based project with a lot of dependencies; the project is normally meant to be developed in Eclipse but I need to work on it from the command line.
How to build+execute the project in a sane way? Something like mvn run, but of course Maven is not meant for running Java projects (for some reason).
The problem is specifying all the dependencies on java's commandline, I don't even know how to autogenerate that. I can currently deal with it using the assembly:single maven plugin (using the jar-with-dependencies descriptor) which will package the dependencies to a single .jar for me.
However, there really is a lot of dependencies and the assembly phase can take about two minutes, greatly disrupting my hack-test cycles so I'm looking for other ways to run the project with minimum build overhead - any recommendations, please?
Note: One possibility is running it in Eclipse once and capturing the java commandline. However, that's just a one-time hack, not a general solution in case I change pom.xml later or come to another project from the suite without Eclipse access anymore.
Have a look at the maven exec plugin
mvn exec:java -Dexec.mainClass="com.example.Main"
if you do this frequently, you can of course configure it via plugin configuration.
Regarding finding out project dependencies - you can use maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
If you want to put them into file it'd be smth like
mvn dependency:list > dependencies.txt
See this question: How can I create an executable JAR with dependencies using Maven?. You can use the dependency-plugin to generate all dependencies in a separate directory before the package phase and then include that in the classpath of the manifest.
I see three solution to this:
onejar-maven-plugin - faster than assemlby with jar-with-dependencies descriptor
With onejar-maven-plugin, you'll (...) get a nice clean super jar with the dependency jars inside.
Spring Boot Maven Plugin - but this is dedicated to Spring projects
Maven Assembly Plugin with custom descriptor. This custom descriptor should grab all dependencies into lib folder, maven-jar-plugin should set Class-Path in Manifest.fm according to this new location. After this you can simply execute your program or zip your jar with lib folder as distribution.
After this is possible to run your program on your computer or any other with one command:
java -jar myjar.jar
I have a pom file that builds a standalone application that leverages a variety of Spring modules, in particular it uses the integration-file module. Originally my pom file used the Maven Assembly plugin but the uber jar it created didn't run correctly. Further research seems to indicate that there is a bug in the assembly plugin that basically messes up the dependencies in the uber jar. The recommended workaround is the Shade plugin, which is working for me.
However, the assembly plugin is able to create a zip file that contains the uber jar and other resources (properties files, scripts, etc). You can then use that zip to unzip it and run your script which will call your jar and pass in the other items (as example). As far as I can tell the shade plugin does not do this additional feature.
I've tried combining the shade and assembly plugins using profiles but I can't figure out how to get it to use the shade plugin to build the uber jar and then afterwards, use the assembly plugin to build the zip with the other stuff.
Has anyone done anything similar? I just need to be able to create my uber jar and then zip up the uber jar with the scripts, xml and other items.
Is there a way to run the assembly plugin without binding it to a phase? If there were, I could run package and run the shade plugin and then afterwards run the assembly plugin independently? That would solve my issue if it were possible.
It's a bit late for this answer, but I have the same scenario as you ("package phase": 1. Build uber-jar with shade, 2. Pack it into assembly zip) and all I had to do is alter the order in which plugins are specified in pom.xml.
If shade is specified before assembly, it gets executed before, for the same phase.
It is a common practice to use a separate module in a multimodule project just for assembling the zip. There's also the appassembler-maven-plugin which might be interesting for you (I've never used it myself, though).
About running a plugin without a phase: that's always possible. Execute the full name as specified on the goal-page. In this case org.apache.maven.plugins:maven-assembly-plugin:2.4:single, or in short assembly:single.
Don't try o solve this with profiles, they aren't meant for that.