运行Spring boot fat JAR

时间:2014-11-27 09:49:45

标签: spring-boot uberjar



C:\Users\sinpik\Desktop\jar\extract>java -jar PackageProject-client.jar
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at PachName.Application.main(Application.java:14)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more




我在Spring Boot中创建了一个示例应用程序,它在IDE中正常运行。我想将它打包为胖JAR并通过命令提示符运行它。我该怎么做?我正在使用java -jar JarName.jar运行它。 这是我的构建脚本:

buildscript {
    ext {
        springBootVersion = '1.1.9.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot' 
apply plugin: 'eu.appsatori.fatjar'

jar {
    baseName = 'demo'
    version = '0.0.1-SNAPSHOT'
}


fatJar{
    manifest {
     attributes 'Implementation-Title': 'Gradle Jar File Example',
    //      'Implementation-Version': version,
        'Main-Class': 'PachName.Application'
     }

}

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
    }
}

fatJarPrepareFiles {
    include 'application.properties'

  }

task wrapper(type: Wrapper) {
    gradleVersion = '1.12'
}

0 个答案:

没有答案