How do I assemble a console application with Maven without unpacking all dependencies?
Suppose I have the following directory layout in a Maven project:
src/
|-- main
| |-- bin
| | |-- run.cmd
| | `-- run.sh
| |-- etc
| | |-- common-spring.xml
| | |-- log4j.xml
| | `-- xml-spring.xml
| `-- java
| `-- com
...
I would like to build a zip file that, when unzipped, produces something like this:
assembly
|-- bin
| |-- run.cmd
| `-- run.sh
|-- etc
| |-- common-spring.xml
| |-- log4j.xml
| `-- xml-spring.xml
`-- lib
|-- dependency1.jar
|-- dependency2.jar
...
where `run.xx' are executable shell scripts that will call my main application and put all dependencies on the classpath.
Is this possible with some of the `official' Maven plugins, e.g. maven-assembly-plugin?
Asked by: Emily341 | Posted: 21-01-2022
Answer 1
I use the AppAssembler plugin to get something similar. Example:
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<configuration>
<programs>
<program>
<mainClass>com.acme.MainClass</mainClass>
<name>app</name>
</program>
</programs>
</configuration>
</plugin>
</plugins>
Answered by: Victoria804 | Posted: 22-02-2022
Answer 2
I've used the maven-assembly-plugin to acheive something similar in a project. I wanted a zip file to be built during the package phase, instead of manually calling assembly:assembly. Here's what I came up with:
/src/assemble/distribution.xml:
<assembly>
<id>distribution</id>
<!-- specify the output formats -->
<formats>
<format>zip</format>
</formats>
<!-- include all runtime libraries in the /lib folder of the output file -->
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<!-- include all *.jar files in the target directory -->
<fileSet>
<directory>target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<!-- include all files in the /conf directory -->
<fileSet>
<outputDirectory></outputDirectory>
<includes>
<include>conf/**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
/pom.xml
...
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assemble/distribution.xml
</descriptor>
</descriptors>
</configuration>
<!-- append assembly:assembly to the package phase -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
...
Answered by: Brooke833 | Posted: 22-02-2022Answer 3
The maven-assembly-plugin can also copy the dependencies into your assembly, by including something like the below in your assembly descriptor file:
<dependencySets>
<!-- Copy dependency jar files to 'lib' -->
<dependencySet>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*:jar:*</include>
</includes>
</dependencySet>
</dependencySets>
Answered by: Oliver111 | Posted: 22-02-2022
Answer 4
The appassembler generates the 'run.xx' files for you.
If you have already created the shell scripts yourself you can use the maven-assembly-plugin to create the zip file. To gather the dependencies you can use maven-dependency-plugin.
Answered by: Aldus164 | Posted: 22-02-2022Similar questions
eclipse - Whats best way to package a Java Application with lots of dependencies?
I'm writing a java app using eclipse which references a few external jars and requires some config files to be user accessable.
What is the best way to package it up for deployment?
My understanding is that you cant put Jars inside another jar file, is this correct?
Can I keep my config files out of the jars and still reference them in the code? Or should the path to the con...
Package and run a Java application with spring dependencies
I built a stand-alone Java application that has a bunch of dependencies (Apache Commons libs, etc) as well as a dependency on the Spring framework, which in turn has a bunch of dependencies.
I built this in Eclipse, where it runs fine. Now I need to deploy it to production and so I'm trying to figure out the best way to package it with all dependencies and also how to even invoke the thing (it will be invoked from ...
java - How to mange dependencies for a Glassfish JavaEE client application?
JBoss has the jbossall-client.jar which can be used in client applications for JNDI lookups and more... It is available in the JBoss maven repository.
How should one do it when using Glassfish 3 in a dependency managed environment?
The
classpath - How to run java application built with buildr and using dependencies?
I have successfully created a buildfile which builds my application. There is a dependency, which is automatically downloaded to ~/.m2/repository/ and provided at compile time. I can now easily build the application.
The question is: how do I easily start this application with the specified dependencies in the class path?
My build file is:
repositories.remote << 'http://repo1.maven.org...
deployment - Creating a Java application that downloads its own dependencies
I'm interested in how to distribute a Java application that has a lot of dependencies (specified in a pom.xml in Maven).
Obviously it would be possible to just package everything in one big .jar file. However that seems wasteful, since an update of the application would require sending a new copy of all the dependencies as well.
So I'm looking for a way of distributing the app that does the following:
...
java - How do you create a standalone application with dependencies intact using Maven?
I have a desktop Java application built using Maven 2 (but I could upgrade to Maven 3 if that helps) with a number of open source dependencies. I'm now trying to package it up as a standalone to make it available to end users without them needing to install maven or anything else.
I've successfully used maven-assembly-plugin to build a single jar containing all dependencies but this is not really what I want becau...
java - Spring web application, Injection of autowired dependencies fail
I am setting up a simple Hello World web application with Spring and Maven.
Somehow, I keep getting a BeanCreationException when trying to autowire my test bean.
Hello Bean:
package de.dijon.test;
public class HelloBean {
private String name;
public void setName(String name) {
this.name = name;
}
public String getHello() {
return ("Hello " + name);
}
}
web.xml:
java - Showing missing dependencies while deploying an application in JBoss AS 7
Getting following exception while deploying the ear file whose structure as follow :
Ear comprise of ejb module(EJB + JPA) and war module
//stack trace
11:47:09,207 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2)
JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version
9.0)
11:47:09,290 INFO [org.jboss.web] (MSC service threa...
java - dependencies for jsf (like servlet) prevent application from starting
I have quite a big Java application that uses some jobs and a lot of http and db activity. This app was build using maven, has quite a lot dependencies and runs on tomcat 6 - good thing is, it works.
However, I now wanted to add some JSF functionality, namely I wanted to be able to manually start and stop quartz jobs from a website and so I activated two more dependencies in my pom.xml:
<!--...
java - Build and package application and dependencies in separate jars with Maven
I am looking for a pom.xml configuration that would package my application in one jar and all application dependencies in another jar. I looked at the maven-assembly-plugin and with the following configuration i was able to build an application jar and then an application jar with all dependencies, but i needs the dependencies jar to not contain my application:
<plugin>
<artifactId>maven-ass...
eclipse - Whats best way to package a Java Application with lots of dependencies?
I'm writing a java app using eclipse which references a few external jars and requires some config files to be user accessable.
What is the best way to package it up for deployment?
My understanding is that you cant put Jars inside another jar file, is this correct?
Can I keep my config files out of the jars and still reference them in the code? Or should the path to the con...
java - How do I track plugin dependencies in maven2?
I am trying to locate an evil plugin that includes a stoneage version of a certain jar file. How do I do that ?
java - Read Jena OntModel with Dependencies
I'm new to the concept of ontology and Jena, so I'm not sure I'm phrasing this correctly..
I need to read a series of connected owl files (by namespace dependencies?) into an in memory Jena model (OntModel?) so inference can be run. How do I do this? Does the order of the files matter? Do I need to call a specific method to "run the inference engine"?
Package and run a Java application with spring dependencies
I built a stand-alone Java application that has a bunch of dependencies (Apache Commons libs, etc) as well as a dependency on the Spring framework, which in turn has a bunch of dependencies.
I built this in Eclipse, where it runs fine. Now I need to deploy it to production and so I'm trying to figure out the best way to package it with all dependencies and also how to even invoke the thing (it will be invoked from ...
Tool to remove unnecessary dependencies in a Java project
I have a Java project that currently has a lot of JARs in its libraries directory, which are all included in the resulting package when building. I know, however, that some of these libs are never referenced in the project.
Is there a tool that can search for libs that are not referenced within the project? I guess there must be something in that sense.
BTW, an Eclipse plugin would be awesome.
EDIT:...
java - How To Check Dependencies Between Jar Files?
I recently have taken the support and programming of a web system written in JSF. The code is kind of messy and redundant, and yes, no documentation exists.
The system has over 40 jar libraries, and most of them are redundant due to old versions and testing. To remove one jar, I must check that it's not imported in the code, so I searched the code for the jar import path (I'm using IntelliJ IDE), made sure that it...
java - What is Spring's Minimum Dependencies for Dependency Injection?
What are the minimum dependencies required to just use Spring's dependency injection (core framework only)? I'm using Spring for a standalone application, and I'd like to minimize the number of dependencies that I have to ship with the application.
I suppose I could systematically remove a Jar and see if the application breaks, but it would be much better if someone had a definitive answer.
Oh, and I'm usi...
hibernate - Java - getting jar dependencies right
I'm relatively new to Java & maven, and so to get to know my way around, I decided to do a project as a means for learning.
I picked a pretty common stack :
Java 1.6
Hibernate (with annotations)
Spring (with annotations)
JUnit 4
Tomcat
Oracle XE / In-mem hsqldb
By far one of the biggest problems I've experienced is getting the correct co...
java - ANT - Run a single target but without dependencies
I know how to run a single target in ANT, but it also checks the "depends" attribute and runs those before the target. Is there a way to prevent this or a way to structure my ANT file so that I can do this more easily?
java - How can I visualize jar (not plugin) dependencies?
I am currently refactoring a large Java application. I have split up one of the central (Eclipse) projects into about 30 individual "components", however they are still heavily inter-dependent. In order to get a better idea of what depends on what I am looking for some way to graph the compile time dependencies.
All tools I have found so far are capable of graphing package or class dependencies or the dependencies ...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)