问题描述:
使用Gradle管理项目依赖时,点击"Build"在/libs下生成"xxxx.jar"后
直接使用:java -jar xxxx.jar 报错:xxxxxxx 没有主清单属性。
解决方案
1. 解决方案:修改"build.gradle"配置,如下所示↓:
buildscript {
ext{
springBootVersion = '2.0.2.RELEASE'
springCloudVersion = 'Finchley.RELEASE'
}
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
group 'com.xxx'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
version = '1.0.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
ignoreFailures = true
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
compile 'org.springframework.boot:spring-boot-starter-web'
}
2. 接下去在IDEA中右边的Gradle中点击--->clean--->build ,清理并编译项目重新
生成"xxxxx.jar",然后到生成的build/libs 下找到xxxxx.jar 并运行此jar包测试:
java -jar xxxxx.jar
----------->此时正常执行程序并可实现成功访问。