简体   繁体   中英

Maven package with dependencies

I am developing a project with Spring framework, and I use Maven to build it.

This project is going to be deployed in a embedded Linux device not connected to the Internet. I see Maven is not packaging dependencies in the generated JAR and I need Maven Shade Plugin for that, but my question is about the common way to deploy a Maven project in target (ie a servlet server) in a striaghtforward way manner.

Is the usual way to use maven command line interface in target to download and execute the software or using JRE indicating a classpath?. My plan is to use rc.d and launch jamvm -cp lib/*.jar:. my.package.Program jamvm -cp lib/*.jar:. my.package.Program but I am not sure is the best way or I should deploy my dependencies out of the JAR file.

Yes, maven-shade-plugin is a good choice to build the so-called "uber" jar if you want your app to be "self-contained". This plugin, maven-shade-plugin creates the JAR that is expected to be free of any side effects. Since the shade phase binds the package goal in standard build lifecycle of Maven, mvn package should build the uber jar with the finalname that you provide in its config. There are several examples to do this (including for example, specifying the "main class"). This way, you can perhaps do jamvm -jar path/to/uber.jar since the main class would be in the JAR file's manifest( although I haven't tried jamvm myself ).

One possible alternative is to rely on what are called as runtime dependencies which need not be packaged with your app. For example, say you know that your runtime (eg the web container that you have on the device) has lots of JAR files for your dependencies already available, then you can piggyback the web container for them and not repackage them in the uber JAR. See Maven's runtime dependency scope for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM