下面是我的项目的build.gradle文件的所有内容,注意高亮部分是关键:

group 'com.xbs'
version '1.0-SNAPSHOT' apply plugin: 'java'
apply plugin: 'idea' sourceCompatibility = 1.8 ext {
profile = System.getProperty("env") ?: "dev"
println "[current profile]:" + profile
} repositories {
mavenCentral()
} dependencies {
compile group: 'org.postgresql', name: 'postgresql', version: '9.4-1201-jdbc41'
mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.5'
mybatisGenerator 'mysql:mysql-connector-java:5.1.32'
mybatisGenerator 'tk.mybatis:mapper:3.3.9'
compile group: 'joda-time', name: 'joda-time', version:'2.5'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.3.2'
compile group: 'org.apache.commons', name: 'commons-io', version:'1.3.2'
compile group: 'commons-net', name: 'commons-net', version:'3.3'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.4.2'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.3.5'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.6.4'
compile group: 'org.mybatis', name: 'mybatis', version:'3.2.8'
compile group: 'org.mybatis', name: 'mybatis-spring', version:'1.2.2'
compile group: 'com.github.miemiedev', name: 'mybatis-paginator', version:'1.2.15'
compile group: 'com.github.pagehelper', name: 'pagehelper', version:'3.4.2'
compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.32'
compile group: 'com.alibaba', name: 'druid', version:'1.0.9'
compile group: 'org.springframework', name: 'spring-context', version:'4.1.3.RELEASE'
compile group: 'org.springframework', name: 'spring-beans', version:'4.1.3.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version:'4.1.3.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version:'4.1.3.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version:'4.1.3.RELEASE'
compile group: 'jstl', name: 'jstl', version:'1.2'
compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3.1'
compile group: 'redis.clients', name: 'jedis', version:'2.7.2'
compile group: 'org.apache.solr', name: 'solr-solrj', version:'4.10.3'
compile group: 'com.alibaba', name: 'fastjson', version:'1.2.4'
compile group: 'org.springframework.integration', name: 'spring-integration-kafka', version:'1.3.0.RELEASE'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version:'1.1.3.RELEASE'
compile group: 'org.apache.kafka', name: 'kafka_2.10', version:'0.10.0.0'
compile 'com.mashape.unirest:unirest-java:1.4.9'
testCompile group: 'junit', name: 'junit', version:'4.12'
} sourceSets {
main {
resources {
srcDirs = ["src/main/resources", "env/$profile"]
}
}
} jar {
String someString = ''
configurations.runtime.each {someString = someString + " lib//"+it.name}
manifest {
attributes 'Main-Class': 'com.xbs.AppMain'
attributes 'Class-Path': someString
}
}
//清除上次的编译过的文件
task clearPj(type:Delete){
delete 'build','target'
}
task copyJar(type:Copy){
from configurations.runtime
into ('build/libs/lib')
}
//把JAR复制到目标目录
task release(type: Copy,dependsOn: [build,copyJar]) {
// from 'conf'
// into ('build/libs/eachend/conf') // 目标位置
}

展开右侧的Gradle侧边栏,找到在other下可以看到clearPj,copyJar以及release,双击release即可打jar包(它默认会执行copyJar,就是把所有的第三方依赖包放到lib目录下):

如果看到控制台输出"BUILD SUCCESSFUL",说明打包成功:

打好的jar默认放在项目中的build目录中:

打开jar包所在目录,可以使用反编译工具查看jar包中的目录结构和文件内容:

打开命令行窗口,使用java -jar命令来执行jar包:

在IDEA中使用gradle配置打可执行jar包[可执行jar与其所依赖的jar分离]的更多相关文章

  1. maven项目引入外部第三方jar包,引入、本地编译、第三方jar一起打到jar中、在linux机器中解决classnotfound(配置classpath),笔记整理。

    文章目录 引用的第三方jar的目录结构(示例) 引入第三方jar进行dependency使项目内能import 本地编译 第三方jar一起打到jar中 在linux机器中解决classnotfound ...

  2. eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错? java.lang.ClassNotFoundException: com.branchitech.app.startup.AppStartupContextListener java.lang.ClassN

    eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错?java. ...

  3. 【Gradle】配置中引用的jar包版本后面自动加冒号导致引入jar包失败的问题/gradle中引用jar包版本不一致的问题/gradle中引用jar失败的问题 解决方法

    idea中 gradle中 引用jar包,版本后面默认加:的问题 gradle中引用jar包版本不一致的问题 gradle中引用jar失败的问题 如上题目所示,三个问题其实都是同一样的简单又恶心,因为 ...

  4. java eclipse打jar包和执行jar中的main函数

    jar包使用eclipse打包步骤 右键需要打包的项目->选择Export 到这里有两种打包的方式 1.如果项目中没有使用其他第三方包等,则直接选择下图中的第一种即可(JAR file) 2.如 ...

  5. maven本地仓库中存在jar包,但编译不成功,显示jar包不存在

    介绍一下背景,项目要迁移进坑人的离线的内网开发,将在同事那编译通过的代码和maven仓库拷进内网,打算编译通过之后再上传私服,结果配好maven之后,本地库中的部分jar包显示没有引入,如下面的波浪线 ...

  6. 【android studio】 gradle配置成本地离线zip包

    http://blog.csdn.net/jingleye/article/details/52689260       关键词:distributionUrl修改成本地路径,android stud ...

  7. 深入Jar包:Gradle构建可执行jar包与访问jar包中文件夹与文件

    前言 Java的跨平台功能听起来很诱人可口,号称"Write Once,Run Everywhere",实际上是"Run Once,Debug Everywh" ...

  8. spring入门(六)【springMVC中各数据源配置】

    在使用spring进行javaWeb开发的过程中,需要和数据库进行数据交换,为此要经常获取数据库连接,使用JDBC的方式获取数据库连接,使用完毕之后再释放连接,这种过程对系统资源的消耗无疑是很大的,这 ...

  9. Eclipse中Ant的配置与测试 转

    欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...

随机推荐

  1. APP-7-百度地图移动轨迹

    1.代码部分 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

  2. The Google File System——论文详解(转)

    “Google文件存储系统(GFS)是构建在廉价服务器之上的大型分布式系统.它将服务器故障视为正常现象,通过软件方式自动容错,在保证系统可用性和可靠性同时,大大降低系统成本. GFS是Google整个 ...

  3. unity 解决ScrollRect嵌套滚动问题

    在子级有ScrollRect组件的对象添加以下脚本: using UnityEngine; using System.Collections; using UnityEngine.UI; using ...

  4. MVC之Model元数据

    Contronoller激活之后,ASP.NET MVC会根据当前请求上下文得到目标Action的名称,然后解析出对应的方法并执行之. 在整个Action方法的执行过程中,Model元数据的解析是一个 ...

  5. 最邻近算法(KNN)识别数字验证码

    应用场景   对于简单的数字型验证码的自动识别.前期已经完成的工作是通过切割将验证码图片切割成一个一个的单个数字的图片,并按照对应的数字表征类别进行分类(即哪些图片表示数字7,哪些表示8),将各种数字 ...

  6. Android Studio3.1.2编译时Java Compiler出错:Warning: Failed to parse host proxy3.bj...

    删除gradle.properties中的代理设置... #移除下面配置systemProp.http.proxyHost=proxy3.bj.petrochina systemProp.http.p ...

  7. sp_executesql 或者 EXECUTE 执行动态sql的权限问题

    当 sp_executesql 或 EXECUTE 语句执行字符串时,字符串将作为它的自包含批处理执行.SQL Server 会将字符串中的一个或多个 Transact-SQL 语句编译为独立于批处理 ...

  8. week06 08 postman 测试jsonrpc

    用postman来测试rpc需要添加特别的字段 ’ { "jsonrpc":"2.0", "id":"123", &qu ...

  9. .gitignore设置

    git提交的时候一直提示 e/.idea/workspace.xml文件冲突, 这个文件是IDE编辑的时候自动带的文件,这个文件在提交的时候是不需要上传到git中的 这个时候我们需要这种.gitign ...

  10. js性能提高篇

    ,最后统一将DocumentFragment添加到页面. 该做法可以减少页面渲染dom元素的次数.经IE和Fx下测试,在append1000个元素时,效率能提高10%-30%