Spring Boot Gradle app on Heroku: Unable to access jarfile - java

I have a spring boot gradle app which I could run successfully on my PC by doing:
heroku local
It can also deploy on heroku successfully when I go:
git push heroku master
This is my result:
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
But when I try to access it on heroku, it crashes. The heroku logs says this:
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
Why is it Unable to access jarfile build/libs/myapp.jar ?
When I navigate to that folder on my local PC, the jarfile is there.
I'm running out of ideas on how to solve this.

You don't need to modify your stage task for that.
In your gradle.build file, make sure to give a name to your built artifact like this.
jar {
baseName = 'app'
version = '0.0.1'
}
With that been done, and the following in Procfile, it should just run fine.
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/app-0.0.1.jar
I found that if name is not explicitly defined, heroku seems to name the artifact something like build-{buildNumber}.jar and no wonder it will never find the app.jar.
Also, if not set already, the build pack needs to be set.
heroku config:set GRADLE_TASK="build"

I eventually found a very helpful thread here: Running Spring app built with gradle on Heroku
Which helped me with my problem - this thread seems to be more detail than Heroku's official guide.
You must add the following code to your build.gradle file:
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()
}
Then, point your Procfile to the app.jar:
web: java $JAVA_OPTS -jar app.jar

According to the documentation:
The Gradle buildpack will automatically detect the use of the Spring Boot and Ratpack web frameworks.
The web command should be overridden only if needed. If you're using Spring Boot, you shouldn't need to specify a Procfile at all.
Delete it, and get your app running without further configuration.

A simpler solution:
I was also encountering the same error and it was a serious waste of time for me. Unlike the ones here, I solved the problem as follows.
First of all, we need to know this.
Heroku creates a new version after each build.
For this reason, if you use a command that contains a fixed version definition in the Procfile file like build/libs/app-0.0.1-SNAPSHOT.jar, it will cause an error like this.
2022-03-02T18:19:30.797673+00:00 app[web.1]: Error: Unable to access jarfile build/libs/app-0.0.1-SNAPSHOT.jar
After the build task, Gradle creates 2 jars named app-0.0.1-SNAPSHOT.jar and app-0.0.1-SNAPSHOT-plain.jar under libs/ folder. app-0.0.1-SNAPSHOT.jar is our application including all dependencies. So I first blocked the rendering of app-0.0.1-SNAPSHOT-plain.jar as below.
jar {
enabled = false
}
Then I used the following wildcard definition in Procfile which is not affected by version changes.
web: java $JAVA_OPTS -Dserver.port=$PORT -jar build/libs/*.jar
The problem can also be solved in this way.

For deploying Gradle App on Heroku. Just add below lines in build.gradle file.
task stage(type: Copy, dependsOn: [clean, build]) {
from jar.archivePath
into project.rootDir
rename {
'app.jar'
}
}
stage.mustRunAfter(clean)
This also in build.gradle file for running jar file.
jar {
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF'
manifest {
attributes(
'Main-Class': 'com.heroku.herokudemo.HerokuDemoApplication'
)
}
}
After this create a txt file named Procfile and add the following content.
web: java $JAVA_OPTS -Dserver.port=$PORT -jar build/libs/heroku-demo-0.0.1-SNAPSHOT.jar

Related

When i try to git push heroku i get an error

Error im getting is below, this happens when i do "git push heroku master"
Enumerating objects: 262, done.
Counting objects: 100% (262/262), done.
Delta compression using up to 4 threads
Compressing objects: 100% (232/232), done.
Writing objects: 100% (262/262), 316.61 KiB | 4.34 MiB/s, done.
Total 262 (delta 34), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Gradle app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew stage
remote: Downloading https://services.gradle.org/distributions/gradle-6.0-all.zip
remote: ......................................................................................................................................
remote: Unzipping /app/tmp/cache/.gradle/wrapper/dists/gradle-6.0-all/cra2s42cvogxluqqpvbc5e9xd/gradle-6.0-all.zip to /app/tmp/cache/.gradle/wrapper/dists/gradle-6.0-all/cra2s42cvogxluqqpvbc5e9xd
remote: Set executable permissions for: /app/tmp/cache/.gradle/wrapper/dists/gradle-6.0-all/cra2s42cvogxluqqpvbc5e9xd/gradle-6.0/bin/gradle
remote:
remote: > Configure project :
remote: fatal: not a git repository (or any parent up to mount point /)
remote: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
remote:
remote: FAILURE: Build failed with an exception.
remote:
remote: * Where:
remote: Build file '/tmp/build_24a75868b111767bf7a04169c852fe43/build.gradle' line: 102
remote:
remote: * What went wrong:
remote: A problem occurred evaluating root project 'XXX-bot'.
remote: > Process 'command 'git'' finished with non-zero exit value 128
remote:
remote: * Try:
remote: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
remote:
remote: * Get more help at https://help.gradle.org
remote:
remote: Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
remote: Use '--warning-mode all' to show the individual deprecation warnings.
remote: See https://docs.gradle.org/6.0/userguide/command_line_interface.html#sec:command_line_warnings
remote:
remote: BUILD FAILED in 51s
remote:
remote: ! ERROR: Failed to run Gradle!
remote: We're sorry this build is failing. If you can't find the issue in application
remote: code, please submit a ticket so we can help: https://help.heroku.com
remote: You can also try reverting to the previous version of the buildpack by running:
remote: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
remote:
remote: Thanks,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Gradle app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to be-anmusicnew.
remote:
To https://git.heroku.com/XXX
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/XXX.git'
while executing "git ls-files gradle" the following files are listed
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
and my Procfile looks like this
"worker: java -jar target/Bot.jar"
Under the configure project there is an error:
fatal: not a git repository (or any parent up to mount point /)
so he can't push to that.
Try to modify the urlwhere you want to push

Azure Linux Webapp cannot seem to find deployed Spring .jar from DevOps repo

I have a Spring Web Application in a DevOps repository, with a .yml that looks like this (as generated by the tool in the DevOps web client):
# Build your Java project and deploy it to Azure as a Linux web app
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
variables:
Version: '0.0.1'
# Azure Resource Manager connection created during pipeline creation
azureSubscription: '-snipped-'
# Web app name
webAppName: 'SlackCentralTestApp'
# Environment name
environmentName: 'SlackCentralTestApp'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: MavenPackageAndPublishArtifacts
displayName: Maven Package and Publish Artifacts
pool:
vmImage: $(vmImageName)
steps:
- task: Maven#3
displayName: 'Maven Package'
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: CopyFiles#2
displayName: 'Copy Files to artifact staging directory'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: '**/target/SlackbotTest-$(Version)-SNAPSHOT.?(war|jar)'
TargetFolder: $(Build.ArtifactStagingDirectory)
- upload: $(Build.ArtifactStagingDirectory)
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeployLinuxWebApp
displayName: Deploy Linux Web App
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: SlackCentralTestApp'
inputs:
azureSubscription: 'Azure for Students (4998490e-1bc4-43fc-a370-80744706d1f5)'
appType: 'webAppLinux'
appName: 'SlackCentralTestApp'
package: '$(Pipeline.Workspace)/drop/target/SlackbotTest-$(Version)-SNAPSHOT.jar'
runtimeStack: 'JAVA|11-java11'
startUpCommand: 'java -jar $(Pipeline.Workspace)/drop/target/SlackbotTest-$(Version)-SNAPSHOT.jar'
The deployment process seems to be successful as seen in this screenshot, yet when I take a look at the server log, I sadly get greeted with the following error:
2020-04-14T09:03:55.658599508Z Initializing App Insights applicationinsights-agent-codeless-2.5.0.jar....
2020-04-14T09:03:55.669449167Z STARTUP_FILE=
2020-04-14T09:03:55.676322304Z STARTUP_COMMAND=java -jar /home/vsts/work/1/drop/target/SlackbotTest-0.0.1-SNAPSHOT.jar
2020-04-14T09:03:55.676350305Z No STARTUP_FILE available.
2020-04-14T09:03:55.676428905Z Running STARTUP_COMMAND: java -jar /home/vsts/work/1/drop/target/SlackbotTest-0.0.1-SNAPSHOT.jar
2020-04-14T09:03:55.681352232Z Error: Unable to access jarfile /home/vsts/work/1/drop/target/SlackbotTest-0.0.1-SNAPSHOT.jar
2020-04-14T09:03:55.694784805Z Finished running startup command 'java -jar /home/vsts/work/1/drop/target/SlackbotTest-0.0.1-SNAPSHOT.jar'. Exiting with exit code 1.
This would lead me to conclude that the path as given in the 'startUpCommand' property from the .yml file is incorrect, yet I have not been able to find what the correct path should be.
I have attempted the following:
Specify no directories, only the filename. Leads to the same result, sadly.
Use the 'find' command in Bash to find any .jars on the Web App, which tells me that there are none.
Manually building the application from the Web App does not seem to be an option either, as it's a Java 11 application and the java SE that seems to be included is version 1.8, regardless of the version I specify during the creation of the Web App resource in Azure.

Gitlab CI Artifacts Permanently Moved Error 301?

I just finished setting up Gitlab Ci to use a Docker container with Maven 3 and Java 8 to build my project. The build successfully completes however when I try to save the generated jar file as an artifact, Docker tells me the artifact has been permanently moved....directly after finding the jar file.
This one has me scratching my head.
Here is my Giitlab CI yml file:
image: kaiwinter/docker-java8-maven
before_script:
- apt-get update --fix-missing
- apt-get install -y git
- git clone -v https://github.com/stefaneidelloth/javafx-d3.git /builds/external/javafxd3
- cd /builds/external/javafxd3/javafx-d3
- mvn install
- cd /builds/external/myDemo
build:
script: "mvn -B install"
tags:
- java8
- maven3
artifacts:
paths:
- target/*.jar
And this is the last few lines from the console from the Job.
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.547 s
[INFO] Finished at: 2017-04-06T17:58:06+00:00
[INFO] Final Memory: 34M/462M
[INFO] ------------------------------------------------------------------------
Uploading artifacts...
target/*.jar: found 1 matching files
WARNING: Uploading artifacts to coordinator... failed id=105 responseStatus=301 Moved Permanently status=301 Moved Permanently token=4pf6n8aT
WARNING: Retrying...
WARNING: Uploading artifacts to coordinator... failed id=105 responseStatus=301 Moved Permanently status=301 Moved Permanently token=4pf6n8aT
WARNING: Retrying...
WARNING: Uploading artifacts to coordinator... failed id=105 responseStatus=301 Moved Permanently status=301 Moved Permanently token=4pf6n8aT
FATAL: invalid argument
Job succeeded
I was able to resolve this. Apparently the docker container, although it could ping the gitlab host, couldnt resolve the artifact-uploader domain name specified in the runner. I changed the runner config in /etc/gitlab-runner/config.toml to the IP of the host machine, and the artifacts copied just fine.

Heroku Deploy of Java app fails using Ant Buildpack

I'm trying to deploy the following app to Heroku:
https://github.com/raeffu/ch.bfh.bti7081.s2015.Blue/
I'm using the Ant Buildpack.
After executing
$ git push heroku master
the build is successful and then this error message appears at the end of the log:
remote: BUILD SUCCESSFUL
[.....]
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 236.4MB
remote: -----> Launching... failed
remote:
remote: ! Push rejected, failure creating release
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to healvis.
remote:
To https://git.heroku.com/healvis.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/healvis.git'
The Procfile looks like this:
web: java -jar lib/webapp-runner-8.0.18.0-M1.jar --expand-war --port $PORT target/healvis.war
The log does not reveal any helpful information.
How can I find out more what's going wrong or, even better, how can I fix it?
The problem was the addon shared-database required by the buildpack.
I forked the repository and removed the addon, now it works.

Maven release plugin fails when creating tag

I'm trying to use Maven release plugin 2.0 to tag the version and hopefully deploy the resulting jar to the repository.
I got stuck at release:prepare, getting this cryptic error:
[INFO] Checking in modified POMs...
[INFO] Executing: cmd.exe /X /C "svn --non-interactive commit --file C:\Users\ME~1\AppData\Local\Temp\maven-scm-950614965.commit --targets C:\Users\ME~1\AppData\Local\Temp\maven-scm-35306-targets"
[INFO] Working directory: c:\workspace\release-test-trunk
[INFO] Tagging release with the label release-test-1.3.0...
[INFO] Executing: cmd.exe /X /C "svn --non-interactive copy --file C:\Users\ME~1\AppData\Local\Temp\maven-scm-829250416.commit --revision 1885 http://myserver/myproject/sandbox/release-test/trunk http://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0"
[INFO] Working directory: c:\workspace\release-test-trunk
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to tag SCM
Provider message:
The svn tag command failed.
Command output:
svn: OPTIONS of 'http://myserver/myproject/sandbox/release-test': 200 OK (http://myserver)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20 seconds
[INFO] Finished at: Tue Aug 24 19:31:55 GMT 2010
[INFO] Final Memory: 14M/56M
[INFO] ------------------------------------------------------------------------
The tag folder does exist and is empty
I executed the command mvn clean release:clean release:prepare to be sure have a fresh run
Every time I got the error I executed mvn release:rollback to have everything back to normal
It doesn't seem to be a credentials problem, the pom file is effectively commited with the -SNAPSHOT removed and the scm information switched to the tag folder.
The strange part is I don't understand how the pom file is commited since I did not specify any credentials neither in the pom nor in the settings.xml file located in maven local install
I saw many people having a similar issue but with the folder already exist error message. Mine doesn't tell me what the error is precisely.
Do you have any ideas ?
Many thanks.
EDIT:
#Colin
If I browse svn://myserver/myproject/sandbox/release-test using tortoise svn for example it works fine. However if I type http://myserver/myproject/sandbox/release-test in Firefox the page is not found.
Also I think it should be ok since the pom file gets commited before trying to create the tag.
My scm section in the pom file :
<scm>
<connection>scm:svn:http://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</connection>
<developerConnection>scm:svn:http://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</developerConnection>
<url>http://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</url>
</scm>
I tried removing the "http:" but that didn't work.
The problem isn't really maven here. It's more about svn itself. Maven stops its operation when svn send this error message :
svn: OPTIONS of 'http://myserver/myproject/sandbox/release-test': 200 OK (http://myserver)
Are you absolutly sure about the http://myserver/myproject/sandbox/release-test adress ?
If http://myserver/myproject/sandbox/release-test doesn't exists svn won't commit anything. Just replace the http:// by svn://
<scm>
<connection>scm:svn:svn://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</connection>
<developerConnection>scm:svn:svn://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</developerConnection>
<url>svn://myserver/myproject/sandbox/release-test/tags/release-test-1.3.0</url>
</scm>
Links :
svnforum.org
An SVN error (200 OK) when checking out from my online repo
Tortoise svn Subversion Update Error

Categories