下面是我的项目的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. 多媒体基础知识之PCM数据《 转》

    多媒体基础知识之PCM数据 1.什么是PCM音频数据 PCM(Pulse Code Modulation)也被称为脉冲编码调制.PCM音频数据是未经压缩的音频采样数据裸流,它是由模拟信号经过采样.量化 ...

  2. Haskell语言学习笔记(92)HXT

    HXT The Haskell XML Toolbox (hxt) 是一个解析 XML 的库. $ cabal install hxt Installed hxt-9.3.1.16 Prelude&g ...

  3. Haskell语言学习笔记(19)File IO

    关于IO Action 类型为IO t. 运算时不执行,因而没有任何效果,只有执行时才会有效果,产生副作用. 一个IO Action只有在其他IO Action中才能被执行. 类型为IO t的IO A ...

  4. [原创]delphi在win7下创建共享文件夹源代码

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  5. 0.1Linux系统开发Angular项目一一首次运行环境的安装(chrome ,terminator,git,node)

    首先,保证你已经安装了虚拟机(虚拟机可以用virturalbox或者VM)并安装了ubuntu镜像! 安装Chrome浏览器 安装terminator(可以多开)代替原来的命令行工具 sudo apt ...

  6. vc读取当前路径和读取配置ini文件

    //获取路径 std::string GetApplicationDir() { HMODULE hModule = GetModuleHandleW(NULL); WCHAR wpath[MAX_P ...

  7. unity 数学公式

    Mathf.Abs绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 f ...

  8. CSS 盒子大小

    盒子的宽和高 盒子的大小通过宽和高来指定. 默认情况下,盒子的大小刚好容纳其中的内容. 两个属性设置盒子的宽和高 width 设置宽 height 设置高 示例: 1 2 3 4 5 6 7 8 9 ...

  9. 学习BOS物流项目第十天

    1 教学计划 1.演示权限demo 2.权限概述 a. 认证 b. 授权 3.常见的权限控制方式 a.  url拦截权限控制 b.  方法注解权限控制 4.创建权限数据模型 a.  权限表 b.  角 ...

  10. windows 激活venv问题

    .\ven\Scripts\activate.\ven\Scripts\activate : 无法加载文件 D:\github\ven\Scripts\activate.ps1,因为在此系统上禁止运行 ...