Fat / Uber jars - Using the Shade Plugin

Similar documents
Xmlbeans-maven-plugin Xml Error Loading Schem

Topics covered. Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session. Maven 2

Jaxb2 Maven Plugin Could Not Process Schema

juddi Developer Guide

Content. Development Tools 2(57)

SCA Java Runtime Overview

Setting up a Maven Project

ApplicationComposer. The TomEE Swiss Knife

MAVEN MOCK TEST MAVEN MOCK TEST IV

Maven POM project modelversion groupid artifactid packaging version name

Open source software libraries used in ConnectAll

Tuscany: Applying OSGi modularity after the fact

What is Maven? Apache Maven is a software project management and comprehension tool (build, test, packaging, reporting, site, deploy).

Maven. INF5750/ Lecture 2 (Part II)

Breaking Apart the Monolith with Modularity and Microservices CON3127

Simplified Build Management with Maven

The jpos REST tutorial shows you how to use an out-of-the-box binary distribution of jpos to build a REST server that responds to an /echo call.

Hello Gradle. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

Chapter 1: First steps with JAX-WS Web Services

MAVEN INTERVIEW QUESTIONS

Repository Management and Sonatype Nexus. Repository Management and Sonatype Nexus

I Got My Mojo Workin'

MicroProfile - New and Noteworthy

Red Hat Fuse 7.0 Deploying into Apache Karaf

Administering Apache Geronimo With Custom Server Assemblies and Maven. David Jencks

Microservices To-Go mit Dropwizard

Java Training Center, Noida - Java Expert Program

Unable To The Artifact From Any Repository Maven-clean-plugin

MAVEN MOCK TEST MAVEN MOCK TEST I

Pour aller plus loin : Programmation outillée

Sonatype CLM Enforcement Points - Nexus. Sonatype CLM Enforcement Points - Nexus

Soap Based Web Services In Java Tutorial Eclipse Jboss

IBM. IBM WebSphere Application Server Migration Toolkit. WebSphere Application Server. Version 9.0 Release

Apache TomEE Tomcat with a kick

TOP REASONS WHY YOU SHOULD SWITCH TO MAVEN 3

Usage and Customization Guide OpenL Tablets Web Services Release 5.16

Class Dependency Analyzer CDA Developer Guide

JOSSO 2.4. Weblogic Integration

Usage and Customization Guide. OpenL Tablets Rule Service Release 5.18

maven Build System Making Projects Make Sense

Java EE 6 - Update Harpreet Singh GlassFish Portfolio Product Manager

Usage and Customization Guide. OpenL Tablets Rule Service Release 5.19

Apache Isis Maven plugin

Set up Maven plugins in Eclipse. Creating a new project

Sonatype CLM - IDE User Guide. Sonatype CLM - IDE User Guide

sites</distribsiteroot>

Software Engineering - Development Infrastructure 2. Kristjan Talvar Nortal

IP Log for soa.swordfish

Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

Spring Web Services Tutorial With Example In

Giovanni Stilo, Ph.D. 140 Chars to Fly. Twitter API 1.1 and Twitter4J introduction

Artix Version Release Notes: Java

Red Hat JBoss Fuse 6.3

Oracle Code Day Hands On Labs (HOL) (Install, Repository, Local Deploy, DevCS, OACCS)

Sonatype CLM - CI User Guide. Sonatype CLM - CI User Guide

Cheat Sheet: Wildfly Swarm

4. Check the site specified in previous step to work with, expand Maven osgi-bundles, and select slf4j.api,

Reliable asynchronous web-services with Apache CXF

JBoss SOAP Web Services User Guide. Version: M5

Distributing JavaFX Applications with Java WebStart and Artifactory

Checking Out and Building Felix with NetBeans

JavaLand Dirk Mahler

Webservices In Java Tutorial For Beginners Using Netbeans Pdf

Migrating to Java 9 Modules. Paul Bakker

Introducing Apache Geronimo 1.1. Aaron Mulder CTO, Chariot Solutions Committer, Apache Geronimo

Techniques for Building J2EE Applications

J2EE Development with Apache Geronimo. Aaron Mulder Chariot Solutions

7.1. RELEASE-NOTES-2.0-M1.TXT

gradle : Building Android Apps Mobel Meetup

Red Hat JBoss Fuse 6.2

The Next Generation. Prabhat Jha Principal Engineer

PKI Cert Creation via Good Control: Reference Implementation

Continuous Integration INRIA

Package Management and Build Tools

Oracle Code Day Hands On Labs HOL

Maven Introduction to Concepts: POM, Dependencies, Plugins, Phases

Enterprise Development

Apache Maven: Best Practices

WebLogic Feature Timeline

Apache Maven. Created by anova r&d bvba

Demystifying OSGi bundles Excerpted from

Maven in the wild. An introduction to Maven

Vision of J2EE. Why J2EE? Need for. J2EE Suite. J2EE Based Distributed Application Architecture Overview. Umair Javed 1

Struts 2 Maven Archetypes

JVM Survival Guide. Hadi Hariri

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

J2EE Development with Apache Geronimo 1.1. Aaron Mulder CTO, Chariot Solutions Committer, Apache Geronimo

Apache Geronimo 3.0 Deep Dive

... Apache Maven PDF Plugin v. 1.4 User Guide.... The Apache Software Foundation

Eclipse Ignore Xml Schema Problems >>>CLICK HERE<<<

Oracle Corporation

Agenda. Why OSGi. What is OSGi. How OSGi Works. Apache projects related to OSGi Progress Software Corporation. All rights reserved.

IBM C IBM WebSphere App Server Dev Tools V8.5, with Liberty.

Artix Release Notes: Java

Apache Axis2. Tooling with Axis2

DOC // JAVA TOMCAT WEB SERVICES TUTORIAL EBOOK

Produced by. Agile Software Development. Eamonn de Leastar

Apache Buildr in Action

Java J Course Outline

Developer Walkthrough

Transcription:

Fat / Uber jars - Using the Shade Plugin

Shading the container and the application has some challenges like merging correctly resources (META-INF/services/ typically). Here is a maven shade plugin configuration working for most cases: <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-shade-plugin</artifactid> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <dependencyreducedpomlocation>${project.build.directory/reducedpom.xml</dependencyreducedpomlocation> <transformers> <transformer implementation= "org.apache.maven.plugins.shade.resource.manifestresourcetransformer"> <mainclass>org.apache.tomee.embedded.fatapp</mainclass> </transformer> <transformer implementation= "org.apache.maven.plugins.shade.resource.appendingtransformer"> <resource>meta-inf/cxf/bus-extensions.txt</resource> </transformer> <transformer implementation= "org.apache.openwebbeans.maven.shade.openwebbeanspropertiestransformer" /> </transformers> <filters> <filter> <!-- we don't want JSF to be activated --> <artifact>*:*</artifact> <excludes> <exclude>meta-inf/faces-config.xml</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> <dependencies> <dependency> <groupid>org.apache.openwebbeans</groupid> <artifactid>openwebbeans-maven</artifactid> <version>1.7.0/version> </dependency> </dependencies> </plugin> 1

NOTE see TomEE Embedded page for more information about tomee embedded options. IMPORTANT this shade uses TomEE Embedded but you can do the same with an Application Composer application. TIP if you have META-INF/web-fragment.xml in your application you will need to merge them in a single one in the shade. Note that tomcat provides one which can be skipped in this operation since it is there only as a marker for jasper detection. Then just build the jar: mvn clean package And you can run it: java -jar myapp-1.0-snapshot.jar Fat Jars with Gradle With gradle you can rely on either jar plugin, fatjar plugin or shadowjar plugin. Last one is likely the closer to maven shade plugin so that s the one used for next sample: // run $ gradle clean shadowjar import org.apache.openwebbeans.gradle.shadow.openwebbeanspropertiestransformer buildscript { repositories { mavenlocal() jcenter() dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' classpath 'org.apache.openwebbeans:openwebbeans-gradle:1.7.0' apply plugin: 'com.github.johnrengelman.shadow' group 'org.apache.tomee.demo.gradle' version '1.0-SNAPSHOT' 2

apply plugin: 'idea' apply plugin: 'java' sourcecompatibility = 1.8 repositories { mavenlocal() mavencentral() dependencies { compileonly 'org.projectlombok:lombok:1.16.10' compile 'org.apache.tomee:tomee-embedded:7.0.2-snapshot' // customize exclusions depending your app // first the not used dependencies like JSF, JAXWS, JMS ones def excludeddependenciesgroups = [ // gradle is buggy with poms, scope provided and optional I think 'com.google.code.findbugs', 'com.google.guava', 'javax.annotation', 'javax.ws.rs', 'net.sf.ehcache', 'org.apache.httpcomponents', 'org.ow2.asm', // tomee jaxws, jms, etc... 'commons-codec', 'com.sun.xml.messaging.saaj', 'joda-time', 'junit', 'net.shibboleth.utilities', 'org.apache.activemq', 'org.apache.activemq.protobuf', 'org.apache.myfaces.core', 'org.apache.neethi', 'org.apache.santuario', 'org.apache.ws.xmlschema', 'org.apache.wss4j', 'org.bouncycastle', 'org.cryptacular', 'org.fusesource.hawtbuf', 'org.jasypt', 'org.jvnet.mimepull', 'org.opensaml', 'wsdl4j', 'xml-resolver' ] // then cxf+tomee specific dependencies so we need to be more precise than the group 3

// to not exclude everything def excludeddependenciesartifacts = [ 'cxf-rt-bindings-soap', 'cxf-rt-bindings-xml', 'cxf-rt-databinding-jaxb', 'cxf-rt-frontend-jaxws', 'cxf-rt-frontend-simple', 'cxf-rt-security-saml', 'cxf-rt-ws-addr', 'cxf-rt-wsdl', 'cxf-rt-ws-policy', 'cxf-rt-ws-security', 'openejb-cxf', 'openejb-webservices', 'tomee-webservices', 'geronimo-connector', 'geronimo-javamail_1.4_mail' ] shadowjar { classifier = 'bundle' // merge SPI descriptors mergeservicefiles() append 'META-INF/cxf/bus-extensions.txt' transform(openwebbeanspropertiestransformer.class) // switch off JSF + JMS + JAXWS exclude 'META-INF/faces-config.xml' dependencies { exclude(dependency { excludeddependenciesgroups.contains(it.modulegroup) excludeddependenciesartifacts.contains(it.modulename) ) // ensure we define the expected Main (if you wrap tomee main use your own class) manifest { attributes 'Main-Class': 'org.apache.tomee.embedded.fatapp' Then run: gradle clean build shadowjar and you ll get build/libs/demo-gradle-tomee-embedded-shade-1.0-snapshot-bundle.jar ready to run with: 4

java -jar build/libs/demo-gradle-tomee-embedded-shade-1.0-snapshot-bundle.jar --as-war --simple-log=true Fat Wars Fat Wars are executable wars. Note they can be fancy for demos but they have the drawback to put the server in web resources at packaging time (to ensure the war is actually an executable jar) so adding a filter preventing these files to be read can be needed if you don t already use a web technology doing it (a servlet bound to /*). Here how to do a fat war: 5

<properties> <!-- can be uber (for all), jaxrs, jaxws for lighter ones --> <tomee.flavor>uber</tomee.flavor> </properties> <dependencies> <!--...your dependencies as usual... --> <dependency> <groupid>org.apache.tomee</groupid> <artifactid>tomee-embedded</artifactid> <classifier>${tomee.flavor</classifier> <version>7.0.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.6</version> <configuration> <failonmissingwebxml>false</failonmissingwebxml> <archive> <manifest> <mainclass>org.apache.tomee.embedded.main</mainclass> </manifest> </archive> <dependentwarexcludes /> <overlays> <overlay> <groupid>org.apache.tomee</groupid> <artifactid>tomee-embedded</artifactid> <classifier>${tomee.flavor</classifier> <type>jar</type> <excludes /> </overlay> </overlays> </configuration> </plugin> </plugins> </build> Then just build the war: mvn clean package 6

And you can run it: java -jar myapp-1.0-snapshot.war 7