For executable JARs I do this as well.

Sometimes for simpler projects, I'll add:

               <addClasspath>true</addClasspath>
               <classpathPrefix>lib/</classpathPrefix>

to the JAR plugin. I use the assembly plugin to place everything in its proper place.

That way I can just ship a tar.gz or zip file with all of the bits. Unzip / untar the archive and run java -jar jarfile.jar.

Tweaks can be made to account for a bin directory, a home directory on which to base both logging and classpath starting points, etc. That way you can put the shell / cmd / bat file in the path, set up a location to find other jars, and keep logging in a reasonable place.

. . . just my two cents
/mde/

On 4/25/2021 3:24 AM, Mantas Gridinas wrote:
I second this approach. It's much more simple, maintainble and you retain
the ability to monkeypatch production deployments. You can later chain it
into assembly plugin to produce an archive that contains your launch
scripts, dependencies, configurations, and perhaps even the JDK itself.
If
youre against having launchscripts, you can write classpath into manifest
via archive plugin.

I doubt that uberjars should be used as dependencies at all considering
they usually suffer from split package issue. If yours doesnt, it probably
uses some special classloader, which makes runtime much more complex than
it needs to be.

On Sun, Apr 25, 2021, 12:45 Jim N <northrup.ja...@gmail.com> wrote:

there's nothing that really painlessly replaced the first
maven fatjar since it became outmoded.

that said, i use dependency plugin to dump a lib/ dir even for reactor
builds, and then a shell script that uses that classpath syntax to load a
directory at a time.

this happens with maven exec anyways, just less fragile.

sometimes shade chokes on a manifest glitch and in practice fixing that is
less efficient than a robust lib/ dir

in the parent-most pom if the levels go deeper, verbatim from the
dependency plugin docs, is
```!xml
         <plugins>
             <plugin>
                 <artifactId>maven-dependency-plugin</artifactId>
                 <executions>
                     <execution>
                         <phase>install</phase>
                         <goals>
                             <goal>copy-dependencies</goal>
                         </goals>
                         <configuration>

<outputDirectory>${project.build.directory}/lib</outputDirectory>
                         </configuration>
                     </execution>
                 </executions>
             </plugin>
```
in bin/ of the top level i have the tiniest specific bash runner, easily
ported to windows as well.

```!bash
#!/usr/bin/env bash

set -fx
JDIR=$(dirname $0)/../apprunner
exec java  -classpath "$JDIR/target/*:$JDIR/target/lib/*"
  ${EXECMAIN:=apprunner.MyMain} "$@"
```

often it's a helpful thing to keep these shell scripts handy to record
variaous -XX and -D parameters in the comments or at run time.




Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to