一 可执行和可引用区别
SpringBoot项目内置了Maven代码管理,可以方便我们快捷生成可执行jar,无论是windows还是linux环境,可以简单使用java -jar这种命令是执行jar文件,但是可引用是无法完成的,boot-dev文件并不运行时文件添加在libs文件中,这也是可执行和可引用的区别。
二 Gradle代码管理生成可引用Jar
build.gradle
plugins {
id 'java'
}
group 'com.nkr'
version '1.0'
// 设置 JDK 版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
// 设置编译使用utf-8编码
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
systemProperty "file.encoding", "UTF-8"
}
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
//mavenCentral()
}
dependencies {
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'cn.hutool:hutool-all:5.3.5'
compile 'com.google.code.gson:gson:2.8.0'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.2'
// https://mvnrepository.com/artifact/org.apache.directory.studio/org.apache.commons.codec
//compile group: 'org.apache.directory.studio', name: 'org.apache.commons.codec', version: '1.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar{
doLast {
copy{
from 'build/libs/interactsdk-1.0.jar'
into '../interactsdk_testconsole/libs'
}
}
}
task generateversiontxt(){
doFirst {
def date = new Date().format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("GMT+8"));
def path = project.projectDir.path+"/src/main/resources/version.txt"
def str = project.path + ' '+ date
new File(project.projectDir.path+"/src/main/resources/").mkdirs();
new File(path).write("$str", 'UTF-8')
}
}
compileJava.dependsOn(generateversiontxt)
//jar {
// manifest {
// attributes "Implementation-Title": project.name
// attributes "Implementation-Version": '1.0.0'
// //attributes 'Main-Class': 'com.nkr.idacqTinyConsole'
// }
// from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
// {
// exclude "META-INF/*.SF"
// exclude "META-INF/*.DSA"
// exclude "META-INF/*.RSA"
// exclude "META-INF/LICENSE"
// exclude "META-INF/LICENSE.txt"
// }
// into('assets') {
// from 'assets'
// }
//// if (!configurations.runtime.isEmpty()) {
//// manifest.attributes('Class-Path': '. lib/' + configurations.runtime.collect { it.name }.join(' lib/'))
//// }
//
//
//}
task FatJar(type:Jar, dependsOn:build){
manifest {
attributes "Implementation-Title": project.name
attributes "Implementation-Version": '1.0.0'
//attributes 'Main-Class': 'com.nkr.idacqTinyConsole'
}
from "build/classes/java/main/"
from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
{
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/LICENSE"
exclude "META-INF/LICENSE.txt"
}
into('assets') {
from 'assets'
}
archiveName 'interactsdk.jar'
// doLast{
//// copy{
//// from "$buildDir/libs/idacqC2.jar"
//// into "Z:\\mayun\\android2\\SignalAcknCh\\app\\libs"
//// }
// copy{
// from("$buildDir/libs/idacqC2.jar")
// into("/Users/usr/Code/idacqTinyShell/libs")
// }
// }
}
task dll(type:Exec, dependsOn:FatJar){
workingDir = "$buildDir/libs/"
def myversion = '9.9.9'
def outputname = 'interactsdk.dll'
def mycmd = [
'ikvmc',
'-target:library',
'interactsdk.jar',
//'-recurse:libs',
"-out:$outputname",
//"-version:$myversion",
'-nologo'
]
commandLine mycmd
doLast{
mycmd.each {
print it+' '
}
println ''
println 'generateDll Done '+ workingDir + "/$outputname"
}
}

京公网安备 11010502036488号