<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Bryan

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks
    Most often, we need to build runnable jars for java library, and I go though several solutions, including shadow, and most of them process the dependencies as classes files in jar file which is not what we expected. and what we want are the runnable jar which includes user classes filles as well as all the dependencies jars in jar format. but in this way , we need extra classloader to load the jar libs in jar files and the following has provided the way of doing it.

    and I go though some most importance web pages and found three solutions for it.

    1. Eclipse jarinjarloader https://github.com/raisercostin/eclipse-jarinjarloader

    apply plugin: 'java'
    apply plugin: 'eclipse'
     
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    version = "4.3.3"

    processResources{
        exclude '**'
    }

    repositories {
        
    //jcenter()
        
    //maven { url "http://clojars.org/repo" }
    }

    dependencies {
        compile files('lib/jlibs-core.jar')
        compile files('lib/jlibs-xml.jar')
        compile files('lib/autonomyPiB.jar')
    }

    //add Class-Path to manifest
    task addDependToManifest {
        doFirst{        
            
    if (!configurations.runtime.isEmpty()) {         
                jar.manifest.attributes('Rsrc-Class-Path'"./ lib/" + configurations.runtime.collect { it.name }.join(' lib/'))
            }
        }
    }
    jar.dependsOn += addDependToManifest
     
    //copy libs to output/mylibs/lib folder
    task copyDependencies(type: Copy) {
        from configurations.runtime
        destinationDir = file('build/mylibs/lib')
    }
    jar.dependsOn += copyDependencies

    jar{
        
    //include contents of output dir
        from "build/mylibs"
        
        from zipTree("lib/jar-in-jar-loader.zip")
        manifest {
            attributes 'Implementation-Title': project.name,
                
    'Class-Path''.',
                
    'Rsrc-Main-Class''com.test.TestA',
                
    'Main-Class''org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader'
        }
    }


    2. spring boot gradle plugin

    we can also use spring boot gradle plugin to build our runnable jars.

    apply plugin: 'java'
    apply plugin: 'eclipse'

    //setting up spring boot gradle plugin which is used for building runnable jars
    buildscript {
        repositories {
            maven { url 'https://repo.spring.io/libs-milestone' }
        }

        dependencies {
            classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE'
        }
    }

    apply plugin: 'org.springframework.boot'
     
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    //version = "4.3.3" 

    tasks.withType(JavaCompile) {
        options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar"
    }

    if (project.hasProperty('env')) {
        println "Target environment: $env"
        sourceSets.main.resources.srcDir "src/main/profile/$env"
    }

    processResources{
        exclude 'TagNames.properties'
    }
     
    repositories {
        
    //jcenter()
        
    //maven { url "http://clojars.org/repo" }
    }
     
    dependencies {
        compile files('lib/jlibs-core.jar')
        compile files('lib/jlibs-xml.jar')
        compile files('lib/autonomyPiB.jar')
    }

    bootRepackage {
        mainClass = 'com.test.TestA'
    }


    3. the one-jar plugin in https://github.com/rholder/gradle-one-jar and this way also works, but if we upgrade to gradle 4.0+ we need to change the OneJar.groovy writeOneJarManifestFile as some function is deprecated.

        File writeOneJarManifestFile(Manifest manifest) {
     
            File manifestFile = File.createTempFile("one-jar-manifest", ".mf")
            manifestFile.deleteOnExit()
            manifest.attributes.put("Main-Class", "com.simontuffs.onejar.Boot")
            manifest.attributes.put("One-Jar-Main-Class", mainClass)
            manifest.attributes.put("One-Jar-Show-Expand", showExpand)
            manifest.attributes.put("One-Jar-Confirm-Expand", confirmExpand)
            manifest.writeTo(manifestFile)
            
            return manifestFile
       }


    //create a runnable jar with all the dependencies using one-jar "gradle aweSomeFunJar"

    apply plugin: 'java'
    apply plugin: 'eclipse'

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.github.rholder:gradle-one-jar:1.0.4'
        }
    }
    apply plugin: 'gradle-one-jar'
     
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    version = "4.3.3" 

    processResources{
        exclude 'TagNames.properties'
    }
     
    repositories {
        
    //jcenter()
        
    //maven { url "http://clojars.org/repo" }
    }

    configurations{
        fatJarBuild
    }
     
    dependencies {

        compile files('lib/jlibs-core.jar')
        compile files('lib/jlibs-xml.jar')
        compile files('lib/autonomyPiB.jar')
        
        fatJarBuild files('lib/jlibs-core.jar')
        fatJarBuild files('lib/jlibs-xml.jar')
        fatJarBuild files('lib/autonomyPiB.jar')
    }

    task awesomeFunJar(type: OneJar) {
      mainClass 'com.test.TestA'
    }

    and I found for the first solution, the runnable jar can read external properties(properties in the same folder as the jar) and for other solution we can only include all our properties in the jar files.

    ----------------------JarInJarLoader Manifest---------------------------
    Manifest-Version: 1.0
    Implementation-Title: dataProcessing
    Rsrc-Class-Path: ./ lib/jlibs-core.jar lib/jlibs-xml.jar lib/autonomyP
     iB.jar
    Class-Path: .
    Rsrc-Main-Class: com.test.TestA
    Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

    ---------------------- spring boot gradle plugin Manifest---------------------------
    Manifest-Version: 1.0
    Start-Class: com.test.TestA
    Spring-Boot-Classes: .;BOOT-INF/classes/
    Spring-Boot-Lib: BOOT-INF/lib/
    Spring-Boot-Version: 1.5.4.RELEASE
    Main-Class: org.springframework.boot.loader.JarLauncher

    ----------------------One Jar Manifest---------------------------
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.9.6
    Created-By: 1.8.0_101-b13 (Oracle Corporation)
    One-Jar-Confirm-Expand: false
    One-Jar-Show-Expand: false
    Main-Class: com.simontuffs.onejar.Boot
    One-Jar-Main-Class: com.test.TestA

    posted on 2017-06-20 19:25 Life is no respector of any genius. 閱讀(604) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲av永久无码精品网站 | 国产亚洲精品拍拍拍拍拍| 成人福利免费视频| 一区二区三区福利视频免费观看| 成人毛片18女人毛片免费96| 国产亚洲情侣一区二区无码AV| 一区二区亚洲精品精华液| 在线观看肉片AV网站免费| 免费少妇a级毛片| 国产JIZZ中国JIZZ免费看| 国产亚洲综合成人91精品| 国产无遮挡裸体免费视频在线观看 | 亚洲一级免费毛片| 亚洲人妖女同在线播放| 女性自慰aⅴ片高清免费| 国产精品亚洲AV三区| 亚洲国产精品碰碰| 成人久久免费网站| 亚洲欧洲日本天天堂在线观看| 国产免费AV片在线播放唯爱网| 亚洲欧美日韩一区二区三区在线| 无码国模国产在线观看免费| 四虎精品成人免费视频| 亚洲精品蜜桃久久久久久| 69视频免费观看l| 亚洲欧美第一成人网站7777 | 亚洲产国偷V产偷V自拍色戒 | 1a级毛片免费观看| 亚洲日韩国产一区二区三区在线 | 亚洲av永久无码精品网站| 日日麻批免费40分钟日本的| 亚洲色欲色欱wwW在线| 亚洲男人第一无码aⅴ网站| 免费国产成人α片| 亚洲精品久久无码av片俺去也| 亚洲日韩在线观看| 97碰公开在线观看免费视频| 麻豆亚洲AV成人无码久久精品 | 亚洲熟妇少妇任你躁在线观看无码| 久久99免费视频| 亚洲av乱码一区二区三区按摩 |