文件结构
再三注意: 在阅读本文之前务必配置Gradle环境。
gradle倒入jar包教程
在开始之前。我认为有必要提醒。你需要先点击FILE->NEW->OTHERS->Gradle project。如果没有Gradle project说明你没有配置gradle环境。
那么什么是Gradle呢?传统的配置环境过程中,不得不去官网下载所需要的jar包,然后build path手动导入。而gradle可以自动下载用到的jar包这样就不用一个一个去官网上下了。至于要用到什么jar包,要在做项目之前就想好(比如说我要用spring来写代码,那么我就要去下载关于spring的jar包)。然后在gradle的配置文件当中写上你要用到的jar包。然后gradle就会自动去帮你下载。Gradle只需要你在build.gradle写好配置代码即可。那么配置代码怎么写呢。我们根据以下代码再做解释。
/*
* This build file was auto generated by running the Gradle 'init' task
* by '18301353897' at '17-8-1 涓嬪崍2:57' with Gradle 2.4
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at http://gradle.org/docs/2.4/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// https://mvnrepository.com/artifact/com.alibaba/fastjson
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.8'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.34'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-undertow
compile group: 'org.springframework.boot', name: 'spring-boot-starter-undertow', version: '1.3.2.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '1.3.2.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.3.2.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.2.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.3.2.RELEASE'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
// https://mvnrepository.com/artifact/com.miglayout/miglayout
compile group: 'com.miglayout', name: 'miglayout', version: '3.7.3.1'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.5'
// https://mvnrepository.com/artifact/com.alibaba/druid
compile group: 'com.alibaba', name: '