복붙노트

[SPRING] Heroku의 Spring Boot Gradle 앱 : jarfile에 액세스 할 수 없습니다

SPRING

Heroku의 Spring Boot Gradle 앱 : jarfile에 액세스 할 수 없습니다

스프링 부트 gradle 앱이 있는데, 다음을 수행하여 PC에서 성공적으로 실행할 수 있습니다.

heroku local

내가 갈 때 heroku에 성공적으로 배포 할 수도 있습니다.

git push heroku master

이것은 내 결과입니다.

Counting objects: 17, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (9/9), 596 bytes | 0 bytes/s, done.
Total 9 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching set buildpack https://github.com/heroku/heroku-buildpack-gradle... done

remote: -----> Gradle app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote:        WARNING: The Gradle buildpack is currently in Beta.
remote: -----> executing ./gradlew build
remote:        :compileJavaNote: Some input files use unchecked or unsafe operations.
remote:        Note: Recompile with -Xlint:unchecked for details.
remote:
remote:        :processResources
remote:        :classes
remote:        :jar
remote:        :bootRepackage
remote:        :assemble
remote:        :compileTestJava UP-TO-DATE
remote:        :processTestResources UP-TO-DATE
remote:        :testClasses UP-TO-DATE
remote:        :test UP-TO-DATE
remote:        :check UP-TO-DATE
remote:        :build
remote:
remote:        BUILD SUCCESSFUL
remote:
remote:        Total time: 11.935 secs
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 72.3MB
remote: -----> Launching... done, v9
remote:        https://myapp.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/myapp.git
   6326429..291326d  master -> master

그러나 heroku에서 액세스하려고하면 충돌이 발생합니다. heroku 로그는 다음과 같이 말합니다.

2015-12-11T17:05:46.096985+00:00 heroku[api]: Deploy 291326d by xxx@gmail.com
2015-12-11T17:05:46.097021+00:00 heroku[api]: Release v9 created by xxx@gmail.com
2015-12-11T17:05:46.378258+00:00 heroku[slug-compiler]: Slug compilation started
2015-12-11T17:05:46.378269+00:00 heroku[slug-compiler]: Slug compilation finished
2015-12-11T17:05:46.755655+00:00 heroku[web.1]: State changed from crashed to starting
2015-12-11T17:05:53.121398+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=5000 -jar  build/libs/myapp.jar`
2015-12-11T17:05:54.260741+00:00 app[web.1]: Error: Unable to access jarfile build/libs/myapp.jar
2015-12-11T17:05:54.784064+00:00 heroku[web.1]: State changed from starting to crashed
2015-12-11T17:05:54.773714+00:00 heroku[web.1]: Process exited with status 1
2015-12-11T17:05:54.788248+00:00 heroku[web.1]: State changed from crashed to starting

jarfile build / libs / myapp.jar에 액세스 할 수없는 이유는 무엇입니까?

로컬 PC에서 해당 폴더로 이동하면 jar 파일이 있습니다.

이 문제를 해결하는 방법에 대한 아이디어가 부족합니다.

해결법

  1. ==============================

    1.나는 결국 여기에서 매우 유용한 스레드를 발견했습니다 : Heroku에 gradle로 빌드 된 Spring 앱 실행

    나는 결국 여기에서 매우 유용한 스레드를 발견했습니다 : Heroku에 gradle로 빌드 된 Spring 앱 실행

    내 문제에 도움이되었습니다.이 스레드는 Heroku의 공식 가이드보다 더 자세하게 보입니다.

    build.gradle 파일에 다음 코드를 추가해야합니다.

    task stage(type: Copy, dependsOn: [clean, build]) {
        from jar.archivePath
        into project.rootDir
        rename {
            'app.jar'
        }
    }
    stage.mustRunAfter(clean)
    
    clean << {
        project.file('app.jar').delete()
    }
    

    그런 다음 Procfile을 app.jar로 지정하십시오.

    web: java $JAVA_OPTS -jar app.jar
    
  2. ==============================

    2.이를 위해 준비 작업을 수정할 필요가 없습니다.

    이를 위해 준비 작업을 수정할 필요가 없습니다.

    gradle.build 파일에서 이와 같이 빌드 된 아티팩트의 이름을 지정하십시오.

    jar {
        baseName = 'app'
        version = '0.0.1'
    }
    

    그 작업이 완료되고 Procfile에서 다음이 정상적으로 실행됩니다.

    web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/app-0.0.1.jar
    

    name이 명시 적으로 정의되지 않은 경우 heroku는 build- {buildNumber} .jar와 같은 아티팩트의 이름을 지정하는 것으로 보이며 app.jar을 찾지 못할 것입니다.

    또한 아직 설정되지 않은 경우 빌드 팩을 설정해야합니다.

    heroku config:set GRADLE_TASK="build"
    
  3. ==============================

    3.설명서에 따르면 :

    설명서에 따르면 :

    웹 명령은 필요한 경우에만 재정의해야합니다. Spring Boot를 사용하는 경우 Procfile을 전혀 지정할 필요가 없습니다.

    삭제하고 추가 구성없이 앱을 실행하십시오.

  4. from https://stackoverflow.com/questions/34228907/spring-boot-gradle-app-on-heroku-unable-to-access-jarfile by cc-by-sa and MIT license