我对gradle很新,希望为REST服务创建构建文件。在阅读Gradle主页和其他一些页面的一些介绍之后,我使用命令gradle init --type=java-project
开始了一个新项目,因为我的服务是基于Java的。该项目的结构已创建,我想将我的.class
文件插入到目录中。这是我的第一个问题:我不知道这种项目的适当结构。在此之后,我将重点放在我添加的依赖关系上。只要我想建立我的项目,就会发生一个错误,这与使用球衣作为技术有关。如果我使用eclipse编译我的服务,那么它工作得很好,所以我的代码工作。为REST-Web服务创建Gradle文件
所以我的2个问题是:
如何建立正确的文件结构?
如何使用的Servlet/WAR编译
这里解决这个问题是我的项目的Eclipse中的结构:
RestWebService
|--Java Resources
| |--src
| |--com.name.restproject.rest
| | |--WebController.java //contains the jersey REST service
| |--com.name.restproject.service
| |--ServiceUtil.java //contains some util methods
|--Libraries
| |--Apache Tomcat v7
| |--asm-3.3.1.jar
| |--EAR Libraries
| |--gson-2.5.jar
| |--jersey-bundle-1.14.jar
| |--JRE SYSTEM Library
| |--json-20151123.jar
| |--Web App Libraries
|--JavaScript Resources
|--build
|--WebContent
|--META-INF
| |--MANIFEST.MF
|--WEB-INF
|--lib
|--fileName.properties //File with Data for ServiceUtil.java
|--configFile.xml //File with Confc for ServiceUtil.java
|--web.xml //Config for the REST paths
我没有计划在何处放置WEB-INF目录中的两个文件。我已经放在projectfolder /src/main/java/com/name/restproject
这里下的结构是该项目的文件的gradle
的build.gradle
apply plugin: 'java'
apply plugin: 'war'
// 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.
mavenCentral()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile group: 'com.google.code.gson', name: 'gson-parent', version: '2.6'
compile group: 'asm', name: 'asm-parent', version: '3.3.1'
compile group: 'com.sun.jersey.glassfish.v3.osgi', name: 'jersey-gf-bundle', version: '1.1.4'
compile group: 'org.json', name: 'json', version: '20151123'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}