[英]Generate a single JAR files with multiple JARs and wsdl files combined together
我正在嘗試生成一個 JAR (salesforce-soap-connection.jar) 文件,我想在我的項目中將其用作依賴項(庫)。 目前,我使用以下命令生成此 jar 文件,然后將生成的 jar 文件推送到我的倉庫中。
java -classpath ./sf/force-wsc-45.0.0.jar:./sf/js-1.7R2.jar:./sf/ST4-4.3.1.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/tools.jar:./sf/antlr-4.7.2-complete.jar com.sforce.ws.tools.wsdlc ./sf/enterprise.wsdl ./sf/salesforce-soap-connection.jar
基本上,我想使用 Gradle 來做到這一點。 (而不是運行上述命令,完全按照使用 Gradle 的命令執行的操作)
上述命令中使用的 jar 文件應從 maven 存儲庫下載,並且只有 enterprise.wsdl 將出現在 project/src/main/resources 文件夾中。
生成的 jar 文件應保存在 project/lib 文件夾中。
這是我的 build.gradle 文件。 請建議下一步該怎么做……
plugins {
id 'scala'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.scala-lang:scala-library:2.11.8'
implementation 'joda-time:joda-time:2.1'
implementation 'org.joda:joda-convert:2.1.1'
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'org.apache.logging.log4j:log4j-api:2.6.2'
implementation 'org.apache.logging.log4j:log4j-core:2.6.2'
implementation 'com.google.cloud:google-cloud-storage:1.52.0'
implementation 'com.google.cloud:google-cloud-bigquery:1.110.0'
implementation 'org.jooq:jooq:3.12.0'
implementation 'org.jooq:jooq-scala_2.11:3.10.5'
implementation 'com.google.apis:google-api-services-bigquery:v2-rev459-1.25.0'
implementation 'org.json:json:20180813'
implementation 'com.google.code.gson:gson:2.8.3'
implementation 'org.yaml:snakeyaml:1.25'
implementation 'com.github.tototoshi:scala-csv_2.11:1.3.6'
implementation 'org.json4s:json4s-native_2.11:3.6.10'
implementation 'org.apache.commons:commons-dbcp2:2.0.1'
implementation 'commons-io:commons-io:2.6'
implementation fileTree('lib')
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes "Main-Class": "com.org.loader.main"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
我能夠用 gradle JavaExec 類型任務解決這個問題。
JavaExec 在子進程中執行 Java 應用程序。
類似於 Exec,但使用給定的類路徑和應用程序 class 啟動 JVM。
我使用 toCopy 作為配置,因此它只是 salesForceJarGenerate 任務,不包含在項目外部依賴項中。
transitive = false 用於停止給定依賴項,以不下載或排除其傳遞依賴項。
在 salesForceJarGenerate 任務中:-
類路徑選項是包括需要為soap-connector.jar提供的依賴項/jar
主要選項是提供主要的 class ,它將.ml 文件轉換為 java 文件。
args 是 arguments。
agrs "{location of your enterprise.xml file}", "output location of your jar file", "location where the intermediate java file will be stored"
更多信息可以在這里的官方文檔中找到!
這是我的最終 build.gradle
plugins {
id 'scala'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.scala-lang:scala-library:2.11.8'
implementation 'joda-time:joda-time:2.1'
implementation 'org.joda:joda-convert:2.1.1'
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'org.slf4j:slf4j-simple:2.0.0'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.12.1'
implementation 'org.apache.logging.log4j:log4j-api:2.6.2'
implementation 'org.apache.logging.log4j:log4j-core:2.6.2'
implementation 'com.google.cloud:google-cloud-storage:1.52.0'
implementation 'com.google.cloud:google-cloud-bigquery:1.110.0'
implementation 'org.jooq:jooq:3.12.0'
implementation 'org.jooq:jooq-scala_2.11:3.10.5'
implementation 'com.google.apis:google-api-services-bigquery:v2-rev459-1.25.0'
implementation 'org.json:json:20180813'
implementation 'com.google.code.gson:gson:2.8.3'
implementation 'org.yaml:snakeyaml:1.25'
implementation 'com.github.tototoshi:scala-csv_2.11:1.3.6'
implementation 'org.json4s:json4s-native_2.11:3.6.10'
implementation 'org.apache.commons:commons-dbcp2:2.0.1'
implementation 'commons-io:commons-io:2.6'
implementation 'com.force.api:force-wsc:54.0.0'
implementation fileTree('lib')
}
configurations {
toCopy
}
dependencies {
toCopy('com.force.api:force-wsc:45.0.0') {
transitive = false
}
toCopy('rhino:js:1.7R2') {
transitive = false
}
toCopy('org.antlr:ST4:4.3.1') {
transitive = false
}
toCopy('org.antlr:antlr-complete:3.5.2') {
transitive = false
}
toCopy('jdk.tools:jdk.tools:1.8') {
transitive = false
}
}
//generates salesforce-soap-connection.jar with the given enterprise.xml file
task salesForceJarGenerate(type: JavaExec) {
classpath = configurations.toCopy
main = "com.sforce.ws.tools.wsdlc"
args "${projectDir}/src/main/resources/enterprise.xml", "${projectDir}/lib/salesforce-soap-connection.jar", "$buildDir/salesforce-gen/"
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes "Main-Class": "com.org.loader.main"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
compileScala.dependsOn salesForceJarGenerate
現在生成的 jar 文件可以通過在依賴項塊中添加以下內容作為依賴項添加。
implementation fileTree("location(directory) of generated jar file")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.