【发布时间】:2016-07-06 13:15:15
【问题描述】:
我是 gradle 的新手,想为 REST 服务创建一个构建文件。在我阅读了 gradle 主页和其他一些页面上的一些介绍之后,我使用命令 gradle init --type=java-project 开始了一个新项目,因为我的服务是基于 Java 的。项目的结构已创建,我想将我的 .class 文件插入到目录中。这是我的第一个问题:我不知道这种项目的正确结构。在此之后,我专注于我添加的依赖项。一旦我想构建我的项目,就会发生一个错误,这与将球衣用作技术有关。如果我用 eclipse 编译我的服务,它工作得很好,所以我的代码可以工作。
所以我的两个问题是:
如何创建合适的文件结构?
如何解决 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 目录中的这两个文件放在哪里。我已经把结构放在了项目文件夹/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'
}
【问题讨论】:
标签: java rest gradle build.gradle