解决idea加gradle手动打jar包后出现“Exception in Application start method”的问题。
在build.gradle中进行打包,可以解决读取资源路径导致的无法运行的问题。具体代码如下:
plugins {
id 'java'
}
group 'demo2'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile( "net.sourceforge.jexcelapi:jxl:2.6.12")
compile( "org.apache.poi:poi-ooxml:3.14")
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
//打jar包需要的配置
jar {
manifest {
attributes(
"Manifest-Version": 1.0,
"Main-Class": "SerialAssistant" //主函数的名称
)
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
into('assets') {
from 'assets'
}
}