问题
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
I have created a sample application in Spring Boot and it is running properly in IDE. I want to package it as a fat JAR and run it through command prompt. How do I do it? I am running it using java -jar JarName.jar
.
This is my build script:
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'
}
来源:https://stackoverflow.com/questions/27167552/running-spring-boot-fat-jar