2016-10-08 105 views
0

我試圖在eclipse Luna中設置gradle以獲得簡單的應用程序,但沒有下載任何jar。任何人都可以給我一個我失蹤的想法嗎? 我在命令行運行gradle clean build併成功編譯: gradle clean build in workspace folder 這是我build.gradle文件的內容:Spring Boot Gradle設置

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'spring-boot' 

jar { 
    baseName = 'sample' 
    version = '0.1.0' 
} 
repositories { 
    mavenCentral() 
} 
sourceCompatibility = 1.8 
targetCompatibility = 1.8 
dependencies { 
    compile("org.springframework.boot:spring-boot-starter-web") 
} 

這是類的與控制器的內容:

package sample; 

import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class SampleController { 

    @RequestMapping("/sample") 
    public String sampleIt(){ 
     return "Hello! Welcome to Spring Boot Sample. "; 
    } 
} 

這是與主要功能類:

package sample; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.ApplicationContext; 

@SpringBootApplication 
public class SampleApplication { 

    public static void main(String[] args) { 
     ApplicationContext ctx = SpringApplication.run(SampleApplication.class, args); 
     System.out.println(ctx.getDisplayName()); 

     System.out.println("This is my first Spring Boot Example"); 

    } 

} 
+0

你有eclipse的gradle插件嗎? –

+0

@ mh-dev是的,我喜歡。我按照以下步驟安裝它:https://pbaris.wordpress.com/2014/08/25/install-gradle-plugin-for-eclipse/。 – user3810317

+0

你是如何將項目添加到eclipse的? –

回答

0

回答評論:

有必要安裝gradle插件,然後導入gradle項目。 (不要忘了點擊'Build Model'按鈕)