2017-10-02 8 views
0

私はSpringブートプロジェクトを持っています。私のリポジトリ内の.ebextensionsフォルダをROOTにコピーする必要がありますGradleを使用して、私のjarファイルのトップレベルのフォルダ)を作成します。 jarファイルのルートディレクトリにない場合、AWS Beanstalkは.ebextensionsフォルダの下にあるnginx confファイルを取得しないことに気付きました。このフォルダすなわちレポの.ebextensions(AWS Beanstalk)ディレクトリをGradleを使用してJava jarファイルのルートディレクトリにコピーしたい

はレポでここに現在ある:私は.ebextensionsフォルダがすることを見つける、

jar { 
    from('.') 
    into("./.") 
    include '.ebextensions/**' 
} 

しかし:私のbuild.gradleで

src 
build.gradle 
gradlew.bat 
gradlew 
build 
README 
.ebextensions 

、私はこのコードを持っていますjarファイルのBOOT-INF/classes /の下にあります。また、BOOT-INF/classes /の下にある他のすべてのクラスファイルも消去します!

BOOT-INFと同じレベルのディレクトリを取得するにはどうすればよいですか?たとえば、次のようになります。

. 
.. 
BOOT-INF 
WEB-INF 
.ebextensions 
<Rest of the source files here> 

ありがとうございます!

P.S.どちらか私はまた、下記の別の解決策を試してみましたが、それは動作しません:

task copyEbExtensions(type: Copy) { 
    from '.' 
    into { getDestDir() } 
    include '.ebextensions' 
} 

PS#2はまた、これはこれは便利である場合には、私のbuild.gradleである:ここでは

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

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'org.springframework.boot' 

jar { 

    baseName = 'oneyearafter' 
    version = '0.1.26' 
} 



task copyEbExtensions(type: Copy) { 
    from '.' 
    into { getDestDir() } 
    include '.ebextensions' 
} 

task wrapper(type: Wrapper) { 
    gradleVersion = '2.0' 
} 


repositories { 
    mavenCentral() 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
    compile("org.springframework.boot:spring-boot-devtools") 

    compile("org.springframework.boot:spring-boot-starter-web") 
    // tag::actuator[] 
    compile("org.springframework.boot:spring-boot-starter-actuator") 
    // end::actuator[] 
    // tag::tests[] 

    compile("org.thymeleaf:thymeleaf-spring4") 

    compile("org.springframework.boot:spring-boot-starter-security") 

    // JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) 
    compile 'org.springframework.boot:spring-boot-starter-data-jpa' 

    // Use MySQL Connector-J 
    compile 'mysql:mysql-connector-java' 


} 


bootRun { 
    addResources = true 
} 
+0

'/ java/main/resources'フォルダにそのファイルをプッシュしようとしましたか? Gradleは、リソースの下のすべてのファイルをjarファイルのルートトップにコピーします。 –

+0

こんにちはTuanBA、はい、私は最初にそれを試みました。これはSpringブートプロジェクトで、元々はsrc/main/resources /の下に.ebextensionsフォルダがありましたが、jarがビルドされると、ルートレベルの.ebextensionsフォルダは表示されません – user1805458

+0

私はカスタムgradle関数を使用しますjarファイルを構築し、 'sources'の下のファイルを' root'にコピーすることができます。私はコメントにすべて投稿することはできませんので、私は回答として投稿します。 –

答えて

0

は私の習慣ですjarファイルを構築するためのgradle関数タスクcompileRunableJarFileを実行してjarファイルをコンパイルします。

apply plugin: 'java' 

sourceSets { 
    main { 
     java { 
      srcDir 'src/java' 
     } 
     resources { 
      srcDir 'src' 
      exclude 'src/java/**/*' 
     } 
    } 
} 

compileJava.dependsOn(processResources) 
jar { 
    duplicatesStrategy = 'exclude' 
    manifest { 
     attributes 'Implementation-Title': title, 
       'Implementation-Version': version, 
       'Implementation-Vendor': vendor, 
       'Created-By': creator, 
       'Main-Class': mainClass, 
       'Manifest-Version': version, 
       'Manifest-Title': title, 
       'Application-Name': title, 
       'JPA-PersistenceUnits': persistenceUnit 
    } 
} 

//create a single Jar with all dependencies 
task compileRunableJarFile(type: Jar, description: 'to create runable JAR.', group: 'compile') { 
    manifest { 
     attributes 'Implementation-Title': title, 
       'Implementation-Version': version, 
       'Implementation-Vendor': vendor, 
       'Created-By': creator, 
       'Main-Class': mainClass, 
       'Manifest-Version': version, 
       'Manifest-Title': title, 
       'Application-Name': title, 
       'JPA-PersistenceUnits': persistenceUnit 
    } 
    baseName = 'app_name_prefix-' + getCurrentTime() 
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 
    with jar 
} 
+0

こんにちはTuan、答えてくれてありがとう、私はあなたが投稿したものに基づいてbuild.gradleを修正しようとしますそれが動作するかどうかを確認します。私も元の質問に私の現在のbuild.gradleを貼り付けました。もしあなたもそれに興味があれば – user1805458

関連する問題