• idea纯java工程使用gradle指定生成jar的Main-Class,idea生成jar


    build.gradle核心代码如下:

    1. jar {
    2. manifest {
    3. attributes "Main-Class": "com.example.sample.Application"
    4. }
    5. from {
    6. configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    7. }
    8. }

    完整代码如下:

    1. group 'com.example.sample'
    2. version '2.1.6'
    3. apply plugin: 'java'
    4. tasks.withType(JavaCompile) {
    5. options.encoding = "UTF-8"
    6. }
    7. sourceCompatibility = 1.8
    8. repositories {
    9. maven { url "https://maven.aliyun.com/repository/central" }
    10. maven { url "https://maven.aliyun.com/repository/jcenter" }
    11. mavenCentral()
    12. // jcenter()
    13. }
    14. dependencies {
    15. testCompile group: 'junit', name: 'junit', version: '4.11'
    16. compile 'org.swinglabs.swingx:swingx-core:1.6.5'
    17. compile "com.squareup.okhttp3:okhttp:3.14.6"
    18. compile 'com.alibaba:fastjson:1.2.70'
    19. compile 'org.quartz-scheduler:quartz:2.3.0'
    20. compile 'com.google.zxing:core:3.4.0'
    21. compile 'com.google.zxing:javase:3.4.0'
    22. compile 'com.google.code.gson:gson:2.8.6'
    23. compile 'mysql:mysql-connector-java:5.1.39'
    24. compile "org.apache.commons:commons-lang3:3.6"
    25. compile "commons-net:commons-net:3.6"
    26. compile "io.github.willena:sqlite-jdbc:3.33.0.1"
    27. compile "io.projectreactor.netty:reactor-netty:0.9.9.RELEASE"
    28. compile "org.apache.commons:commons-compress:1.9"
    29. // 不引入xz依赖会在new SevenZFile的时候报错java.lang.NoClassDefFoundError: org/tukaani/xz/FilterOptions
    30. compile "org.tukaani:xz:1.9"
    31. //解压rar5,所需依赖开始
    32. compile "com.github.axet:java-unrar:1.7.0-8"
    33. compile "com.github.junrar:junrar:4.0.0"
    34. compile "net.sf.sevenzipjbinding:sevenzipjbinding:16.02-2.01"
    35. compile "net.sf.sevenzipjbinding:sevenzipjbinding-all-platforms:16.02-2.01"
    36. compile "org.apache.commons:commons-compress:1.9"
    37. compile "org.tukaani:xz:1.5"
    38. compile "commons-io:commons-io:2.8.0"
    39. compile "com.aliyun.openservices:aliyun-log:0.6.64"
    40. compile "org.apache.poi:poi:4.1.0"
    41. compile "org.apache.poi:poi-ooxml:4.1.0"
    42. compile "net.lingala.zip4j:zip4j:1.3.2"
    43. }
    44. jar {
    45. manifest {
    46. attributes "Main-Class": "com.example.sample.Application"
    47. }
    48. from {
    49. configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    50. }
    51. }

    双击gradle条目下的tasks--build---assemble就可以生成jar;

    生成目录在“项目根目录\build\libs”

  • 相关阅读:
    Java高级-stream流
    esRally国内安装使用避坑指南-全网最新
    AI工具-PPT-SlidesAI
    Flink之常用处理函数
    大模型学习 - 内网环境搭建
    saas系统隐私面单自定义教程
    个人网页设计成品DW静态网页 HTML网页设计结课作业 web课程设计网页规划与设计 Web大学生个人网页成品 web网页设计期末课程大作业
    Egress Gateway
    OpenGL编程学习笔记——glBegin
    计算摄影——图像对比度与色调增强
  • 原文地址:https://blog.csdn.net/chuyouyinghe/article/details/132835838