java - Creating Gradle file for REST-Web Service -
i pretty new gradle , want create buildfile rest-service. after read introduction on gradle homepage , other pages started new project using command gradle init --type=java-project
because service java based. structure of project created , wanted insert .class
files directories. first problem: don´t know proper structure kind of project. after focused on dependencies, added. want build project, error occurs has usage of jersey technology. if compile service eclipse, works fine, code works.
so 2 questions are:
how create proper file structure ?
how fix issue servlet/war-compilation
here structure of project in eclipse:
restwebservice |--java resources | |--src | |--com.name.restproject.rest | | |--webcontroller.java //contains jersey rest service | |--com.name.restproject.service | |--serviceutil.java //contains 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 data serviceutil.java |--configfile.xml //file confc serviceutil.java |--web.xml //config rest paths
i have no plan place 2 files web-inf directory. have placed structure under projectfolder /src/main/java/com/name/restproject
here gradle file of project
build.gradle
apply plugin: 'java' apply plugin: 'war' // in section declare find dependencies of project repositories { // use 'jcenter' resolving dependencies. // can declare maven/ivy/file repository here. mavencentral() } // in section declare dependencies production , test code dependencies { // production code uses slf4j logging api @ 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 dependency favourite test framework want use in tests. // testng supported gradle test task. change // testcompile dependency testcompile 'org.testng:testng:6.8.1' , add // 'test.usetestng()' build script. testcompile 'junit:junit:4.12' }
if want create rest web service gradle build, suggest use spring boot rest
spring boot - building restful web service : http://spring.io/guides/gs/rest-service/
it contains gradle build : https://github.com/spring-guides/gs-rest-service/blob/master/initial/build.gradle
also if want build war instead of jar (which default build configuration), can follow documentation : http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-gradle-packaging
Comments
Post a Comment