Recently started to touch Java and realized that a build tool that seems to work better than Maven is gradle, but you need to build an executable jar package. Check the Internet. The Chinese article is a stereotyped reference to a plugin apply plugin: ' Executable-jar ' (https://github.com/stigkj/ Gradle-executable-jar-plugin), and I don't know who copied who.
But when the build is not recognized this plugin, so look for other methods.
Open eclipse-generated executable jar package with compression software Gradle built with the jar package found MANIFEST.MF file content is not the same (beginner Java, do not know is not just the same here). Required Main-Class
and Class-Path
two attributes.
The eclipse's Gradle plugin was built with the Multiproject template in a project that has this sentence
Jar { manifest.attributes provider: ' My Cool Company '}
The corresponding content appears in the MANIFEST.MF, so check, think not to use ' Executable-jar ' plugin should be the same can solve the problem,
Find this post first
http://blog.csdn.net/hiarcs/article/details/6198945 (Thanks to the author)
The effect is:
Jar { manifest { attributes ' Main-clas ': ' Your. Class ' attributes ' Class-path ': ' Ext.libA.jar ext.libB.jar '//Add all dependencies, separated by spaces
}}
Or find all jar files generated under Libpath:
Jar { manifest { attributes ' Main-clas ': ' Your. Class ' attributes ' Class-path ': New File (LibPath). List (). findAll { it.endswith ('. jar ')}.collect {"$libPath/ $it "}.join (') }}
Because most of my reliance is managed through Gradle. Can not be generated in this way, and personally feel too inflexible. Therefore, FQ to check the outside network,
Find these two posts
Http://forums.gradle.org/gradle/topics/manifest_with_classpath_in_jar_task_for_subprojects
Http://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle
The approximate method is:
Jar { manifest { attributes ("Main-class": "Com.dcx.epep.Start", "Class-path": Configurations.compile.collect {it.getname ()}.join (")) }}
This allows you to copy all the dependent jar files to the executable jar file directory. It is suggested to replace compile with runtime to view Gradle Official document 23.5. Dependency management,runtime contains compile. So replace it.
There is a problem, if I am not dependent, this code will go wrong (https://gist.github.com/simon04/6865179 4th reply)
Task Adddependtomanifest << { if (!configurations.runtime.isempty ()) { jar.manifest.attributes (' Class-path ': configurations.runtime.collect {it.name}.join ('))
At this point, there is another problem, I need to copy the corresponding dependent jar files to the corresponding directory
http://blog.csdn.net/maosidiaoxian/article/details/24456267 This article said some methods, but did not meet my requirements.
Find this post again http://www.zhihu.com/question/20760722 (thanks to the original respondents):
To see what type of project, if it is JEE Web project, you can export the complete war package through the war plugin, you can refer to Gradle's manual if you need to copy the jar package to a custom directory, you can write:
Task Copyjars (type:copy) {from configurations.runtime to ' dist '//target location}
Many of Gradle's tips can be found on this wiki: cookbook-gradle
(reproduced please specify the source http://www.cnblogs.com/yongtao/p/4104526.html)
And I don't want to be the directory where the executable jar resides. So improve it and get my own code. Note that the following code needs to be placed after dependencies.
Jar { manifest { attributes ("Implementation-title": project.name) attributes ("Implementation-version" : version) attributes ("Main-class": "Com.mygoogle.manager.ManageServer") }}task Adddependtomanifest < < { if (!configurations.runtime.isempty ()) { jar.manifest.attributes (' Class-path ': "). manageer_lib/"+ configurations.runtime.collect {it.name}.join (' manager_lib/')) }}jar.dependson + = Adddependtomanifest task Copydependencies (type:copy) {from configurations.runtime destinationdir = File (' Build/libs/manager_lib ')}jar.dependson + = Copydependencies
Other reference articles:
Http://www.gradle.org/docs/current/javadoc/org/gradle/api/java/archives/Manifest.html
Gradle Build executable jar package (reprint please specify source)