Coder Social home page Coder Social logo

Comments (13)

ArtificialPB avatar ArtificialPB commented on June 11, 2024 3

@kustrun and I managed to get it working with Gradle, replicating the Uber JAR structure generated by maven plugin. Here's the minimal required build.gradle example (run buildKumuluzee task).

configurations {
    kumuluzeeLoader { transitive = false }
}

dependencies {
    kumuluzeeLoader 'com.kumuluz.ee:kumuluzee-loader:3.1.0'
}

task repackageKumuluzee {
    /*Unpack and copy kumuluzee loader*/
    copy {
        from zipTree(configurations.kumuluzeeLoader.singleFile).matching { include "**/*.class" }
        into "$buildDir/classes/java/main"
        outputs.upToDateWhen { false }
    }
    /*Create boot loader properties*/
    file("$buildDir/classes/java/main/META-INF/kumuluzee").mkdirs()
    file("$buildDir/classes/java/main/META-INF/kumuluzee/boot-loader.properties").text = "main-class=com.kumuluz.ee.EeApplication"
}
task buildKumuluzee {
    jar {
        baseName = "kumuluz-app"
        archiveName = "${baseName}-${version}.${extension}"
        manifest {
            attributes "Main-Class": "com.kumuluz.ee.loader.EeBootLoader"
        }
        /*Copy project dependencies into lib folder as jars*/
        into("lib") {
            from configurations.runtimeClasspath
        }
    }
    dependsOn repackageKumuluzee
    finalizedBy build
}

from kumuluzee-samples.

MBJuric avatar MBJuric commented on June 11, 2024

We are planning to add Gradle support in the near future.

from kumuluzee-samples.

daggerok avatar daggerok commented on June 11, 2024

please let me know what is wrong with that gradle build script?

plugins {
  id 'java'
  id 'application'
  id 'com.github.johnrengelman.shadow' version '4.0.2'
}
version '1.0.0'
group 'com.github.daggerok'
mainClassName = 'com.kumuluz.ee.EeApplication'
shadowJar.mustRunAfter jar
defaultTasks 'shadowJar'
repositories {
  mavenCentral()
}
dependencies {
  compile 'com.kumuluz.ee:kumuluzee-core:3.0.0'
  compile 'com.kumuluz.ee:kumuluzee-servlet-jetty:3.0.0'
  compile 'com.kumuluz.ee:kumuluzee-cdi-weld:3.0.0'
  compile 'com.kumuluz.ee:kumuluzee-jax-rs-jersey:3.0.0'
  compile 'com.kumuluz.ee:kumuluzee-json-p-jsonp:3.0.0'
}

gradle shadowJar task can build uber jar file, but when I'm running it, I'm getting that error:

# ...skipped
2018-11-21 22:24:14.345 INFO -- com.kumuluz.ee.jetty.JettyFactory -- Starting KumuluzEE on Jetty with 5 minimum and 100 maximum threads
2018-11-21 22:24:14.375 INFO -- com.kumuluz.ee.jetty.JettyFactory -- Starting KumuluzEE on port(s): 8080 [http/1.1]
2018-11-21 22:24:14.427 INFO -- com.kumuluz.ee.jetty.JettyServletServer -- Starting KumuluzEE with context root '/'
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Initializing components
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Found EE component CDI implemented by Weld
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.cdi.CdiComponent -- Initiating Weld
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Components initialized
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Initializing extensions
2018-11-21 22:24:14.432 INFO -- com.kumuluz.ee.EeApplication -- Extensions Initialized
2018-11-21 22:24:14.433 INFO -- org.eclipse.jetty.server.Server -- jetty-9.4.z-SNAPSHOT; built: 2018-06-05T18:24:03.829Z; git: d5fc0523cfa96bfebfbda19606cad384d772f04c; jvm 1.8.0_192-b12
2018-11-21 22:24:14.507 WARNING -- org.eclipse.jetty.webapp.WebAppContext -- Failed startup of context o.e.j.w.WebAppContext@5ed828d{/,file:///private/var/folders/p9/kwk2r83x3hldqvc998h02qkw0000gp/T/kumuluzee-tmp-webapp299415749452541202/,STARTING}
java.lang.ExceptionInInitializerError
        at org.eclipse.jetty.http.MimeTypes$Type.<init>(MimeTypes.java:103)
        at org.eclipse.jetty.http.MimeTypes$Type.<clinit>(MimeTypes.java:58)
        at org.eclipse.jetty.http.MimeTypes.<clinit>(MimeTypes.java:191)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:832)
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
        at org.eclipse.jetty.server.Server.start(Server.java:419)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
        at org.eclipse.jetty.server.Server.doStart(Server.java:386)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at com.kumuluz.ee.jetty.JettyServletServer.startServer(JettyServletServer.java:81)
        at com.kumuluz.ee.EeApplication.initialize(EeApplication.java:368)
        at com.kumuluz.ee.EeApplication.<init>(EeApplication.java:73)
        at com.kumuluz.ee.EeApplication.main(EeApplication.java:85)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
        ... 17 more

seems like problem with org.eclipse.jetty.http.PreEncodedHttpField, but why?

what I'm trying to configure is this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.daggerok</groupId>
  <artifactId>kumuluzee-maven-gradle-app</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.kumuluz.ee</groupId>
        <artifactId>kumuluzee-bom</artifactId>
        <version>3.0.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.kumuluz.ee</groupId>
      <artifactId>kumuluzee-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.kumuluz.ee</groupId>
      <artifactId>kumuluzee-servlet-jetty</artifactId>
    </dependency>
    <dependency>
      <groupId>com.kumuluz.ee</groupId>
      <artifactId>kumuluzee-cdi-weld</artifactId>
    </dependency>
    <dependency>
      <groupId>com.kumuluz.ee</groupId>
      <artifactId>kumuluzee-jax-rs-jersey</artifactId>
    </dependency>
    <dependency>
      <groupId>com.kumuluz.ee</groupId>
      <artifactId>kumuluzee-json-p-jsonp</artifactId>
    </dependency>
  </dependencies>
  <build>
    <defaultGoal>clean package</defaultGoal>
    <plugins>
      <plugin>
        <groupId>com.kumuluz.ee</groupId>
        <artifactId>kumuluzee-maven-plugin</artifactId>
        <version>${kumuluz.version}</version>
        <executions>
          <execution>
            <id>package</id>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Thanks


Regards,
Maksim

from kumuluzee-samples.

urbim avatar urbim commented on June 11, 2024

Hi!

kumuluzee-maven-plugin packages Uber JAR in a custom way, among other things, it uses kumuluzee-loader to bootstrap application. If you want to replicate that behavior in Gradle I think your best option would be to observe Uber JAR created with Maven and try to replicate that with Gradle.

from kumuluzee-samples.

kustrun avatar kustrun commented on June 11, 2024

Hi!

Do you happen to have any further guidelines how to use kumuluzee maven build task with Gradle? Or a possible support for Gradle?

from kumuluzee-samples.

kustrun avatar kustrun commented on June 11, 2024

In order to run different main class you have to edit this boot-loader property:
file("$buildDir/classes/java/main/META-INF/kumuluzee/boot-loader.properties").text = "main-class=com.kumuluz.ee.EeApplication"

jar -> manifest -> attributes -> main-class property MUST NOT BE CHANGED!

from kumuluzee-samples.

MBJuric avatar MBJuric commented on June 11, 2024

@ArtificialPB , @kustrun that's great. Would you be willing to contribute the complete Gradle build solution as a part of the kumuluzEE project? Much appreciated!

from kumuluzee-samples.

ArtificialPB avatar ArtificialPB commented on June 11, 2024

@MBJuric Sure, should we make a PR with the above gradle build example added to the main repository readme file? https://github.com/kumuluz/kumuluzee

from kumuluzee-samples.

MBJuric avatar MBJuric commented on June 11, 2024

@ArtificialPB Yes, please. Also, if you could provide a markdown page that we would include in our Wiki (similar to this one: https://github.com/kumuluz/kumuluzee/wiki/Uber-JAR-support) - "Gradle support".
Also, a full sample in Gradle (such as JAX-RS sample) would be much appreciated, we would publish it in https://github.com/kumuluz/kumuluzee-samples
Thanks.

from kumuluzee-samples.

ArtificialPB avatar ArtificialPB commented on June 11, 2024

@MBJuric Please find the JAX-RS gradle sample in the following repository: https://github.com/ArtificialPB/kumuluzee-jax-rs-gradle

And the Wiki page: https://gist.github.com/ArtificialPB/fa629f321fd3f9d74cc77078da4b4bab

from kumuluzee-samples.

jeusdi avatar jeusdi commented on June 11, 2024

I've used this gradle file in order to build my uber jar.

I'm getting this message:

imagen

from kumuluzee-samples.

daggerok avatar daggerok commented on June 11, 2024

Thank you, @ArtificialPB

I can confirm that I was able use your solution to build kumuluzee fat jar with gradle!

It was little bit challenged migrate currect solution to Gradle Kotlin DSL, so I will left it here just in case if someone will be looking into it:

val kumuluzeeLoader by configurations.creating {
  extendsFrom(configurations["runtime"])
  setTransitive(false)
}

val kumuluzeeVersion: String by project

dependencies {
  kumuluzeeLoader("com.kumuluz.ee:kumuluzee-loader:$kumuluzeeVersion")
  // dependencies
}

tasks {
  register("kumuluzLoader", Copy::class.java) {
    group = "KumuluzEE"
    description = "Add KumuluzEE boot loader"

    from(zipTree(configurations["kumuluzeeLoader"].singleFile).matching {
      include("**/*.class")
    })
    into("$buildDir/classes/java/main")
    outputs.upToDateWhen { false }

    doLast {
      val filename = "$buildDir/classes/java/main/META-INF/kumuluzee"
      file(filename).mkdirs()
      file("$filename/boot-loader.properties")
          .writeText("main-class=com.kumuluz.ee.EeApplication\n", StandardCharsets.UTF_8)
    }
  }

  register("kumuluzJar", Jar::class.java) {
    group = "KumuluzEE"
    description = "Build KumuluzEE uber (fat) jar"

    archiveClassifier.set("all")
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE

    manifest {
      attributes("Main-Class" to "com.kumuluz.ee.loader.EeBootLoader")
    }

    from(configurations.runtimeClasspath.get()) {
      into("lib") // dependencies
    }

    from(sourceSets.main.get().output) // app

    shouldRunAfter("kumuluzLoader")
    dependsOn("kumuluzLoader")
  }
}

defaultTasks("kumuluzJar")

Regards,
Maksim

from kumuluzee-samples.

jeusdi avatar jeusdi commented on June 11, 2024

Is there any roadmap to publish an gradle plugin?

from kumuluzee-samples.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.