I recently deployed my Play App to a Heroku-Server. Running the App in Production-Mode leads to the following Error for each db-table:
Caused by: javax.persistence.PersistenceException: Query threw SQLException:ERROR: relation "tablename" does not exist
Procfile
web: target/universal/stage/bin/myApp -Dhttp.port=${PORT} -DapplyEvolutions.default=true -DapplyDownEvolutions.default=false -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}
I had the same issue deploying the app on another (non-heroku) server. Solved it there by first running in dev-mode to apply the schema and then switch to production.
Is there a reason for having the -DapplyDownEvolutions.default=false in your Procfile command? I'm not sure how that might interact with the -DapplyEvolutions.default=true...it might be worth trying without it.
If that does not work, you could run the evolutions in a one-off process like so:
$ heroku run bash
...
~$ ./target/universal/stage/bin/myApp -DapplyEvolutions.default=true -DapplyDownEvolutions.default=false -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}
Once that completes, you're other dynos should be good to go. However, this creates a period in which the app is deployed, and the evolutions have not been run.
Related
I am trying to set up emacs as scala editor. To that end i am trying to install metals for corresponding modes to work.
However, for some reason or another, metals either failed to install from emacs, or when installed with Coursier, were not responsive from emacs.
So, to explore all the options i decided to use metals source code (from Github? but i have run into the issue of being unable to properly utilize them.
What can i do to make metals available to emacs from the sources?
Currently, i have tried building them with
sbt publishLocal
and then trying to run the jar that was generated, with predictable result:
Exception in thread "main" java.lang.NoClassDefFoundError:
scala/collection/Seq at scala.meta.metals.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
Process metals stderr finished Exception in thread "main"
java.lang.NoClassDefFoundError: scala/collection/Seq at
scala.meta.metals.Main.main(Main.scala) Caused by:
java.lang.ClassNotFoundException: scala.collection.Seq at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
Process metals stderr finished
In my system i have installed with sbt, as suggested by the instructions on scala website.
How should i setup the system so that metals could be launched and used?
You shouldn't need to compile Metals from sources just to use it from Emacs. Check the official documentation: Emacs | Metals, especially the requirements and installation sections. It mentions
Next you have to install metals server. Emacs can do it for you when lsp-mode is enabled in a scala buffer or via lsp-install-server command. Also you can do it manually executing coursier install metals and configuring $PATH variable properly.
If you have problems with the installation, try asking on Scalameta Discord for help. There is a dedicated #emacs-users channel as well.
That said, if you still want to use a locally published Metals artifact for whatever other reason (e.g. contributing to the Metals code and testing changes locally), you should be able to do that. The contributing documentation describes how to work with the codebase and test your local Metals version.
In short, after you ran sbt publishLocal, you need to update the server version setting in your editor and run the Metals: Restart server command. It should pick up the locally published version.
I finally reached the point where my Elastic Beanstalk Instance / Environment got launched. (Java Corretto 11 Platform) Now it fails starting up the provided .jar file.
In the eb-engine.log file, I am not able to find any more error than this:
2021/05/27 11:36:25.889735 [INFO] Executing instruction: StageJavaApplication
2021/05/27 11:36:25.889871 [ERROR] An error occurred during execution of command [app-deploy] - [StageJavaApplication]. Stop running the command. Error: staging java app failed due to invalid zip file
The jar file is a Spring Boot application built with mvn -B package.
Locally the whole thing starts, but crashes afterwards because of not given environment variables (Expected behaviour).
But it seems AWS is not even starting the application..
Any suggestions on this?
Spring Boot apps run nicely on Elastic Beanstalk. However, you do need to set some variables. For example, have you set server-port variable to 5000?
And as you stated, to successfully use a Service Client, you can set environment variables for your creds. Here is an end to end walkthrough that shows how to successfully put a Spring BOOT app that invokes several AWS Services on Elastic Beanstalk.
Creating your first AWS Java web application
PS - your log file mentions a ZIP file. Be sure to create the JAR properly as discussed in the above example.
Just in case someone arrive here looking for an answer about this guy:
Error: staging java app failed due to invalid zip file
I was renaming my service jar in Gradle, using:
tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar> {
archiveFileName.set("service.jar")
launchScript()
}
And ElasticBeanstalk was not happy about the renaming.
When I let it have the default name, then no zip issues and all worked like a charm.
I'm having a node-js app on Heroku using the pdfMerge.js library.
following the documentation I'm using the stream event mechanism as a callback to identify the end of the process
then an exception is thrown :
events.js:167 Error: spawn java ENOENT.
I'm almost sure it's happening because I'm messing required java installation as described here:
pdfmerger combines multiple PDF-files into a single PDF-file. It is a node module that utilizes the Apache PDFBox Library, which the required functionality are distributed along with this module. The only requirement for this module to run, is having Java 6 or higher in the path.
I'm Not familiar enough with Heroku installation/configuration process in order to make it work.
thanks in advance
You can add Java to your app by adding the heroku/jvm buildpack like this:
$ heroku buildpacks:add -i 1 heroku/jvm
Then redeploy with git commit --allow-empty and git push heroku master.
when I run sample IBM Bluemix Liberty for Java application https://github.com/ibmjstart/bluemix-java-postgresql-uploader.git following error:
-----> Downloaded app package (1.9M)
-----> Downloaded app buildpack cache (4.0K)
OK
/var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:101:in build_pack': Unable to detect a supported application type (RuntimeError) from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:74:inblock in compile_with_timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in timeout' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:73:incompile_with_timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:54:in block in stage_application' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:inchdir'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in stage_application' from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in'
FAILED
Server error, status code: 400, error code: 170001, message: Staging error: cannot get instances since staging failed
TIP: use 'cf logs jpu-henryhan --recent' for more information
The top error looks like you left off the -p <path_to_war> parameter when doing a push. If you just push a directory containing a WAR file, it will not be detected by the Java buildpack.
The tip provided in the output of your cf push request is relevant.
TIP: use 'cf logs jpu-henryhan --recent' for more information
Running that command will tail the log files produced during the staging process and let you see what error may have been raised. Often, it can be a missing dependency or a transient failure of some sort.
I just successfully deployed the sample using the "deploy to Bluemix" button and manually via the cf command line tool. Unless you changed the code, it is most likely that this error is a transient failure.
Run following command:
$ cf push jpu- -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p PostgreSQLUpload.war
add the parameter to set the buildpack "-b https://github.com/cloudfoundry/java-buildpack"
I developped my application locally with the default in memory h2 database. Everything works perfectly.
Now I tried to deploy my app by pushing to Heroku.
Before that I added a Procfile to my app's root folder with this line:
web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver
My application.conf looks like:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL"
So I pushed that and then, when I try to access my app i get:
Salieri:addressManager administrator$ heroku ps
=== web (1X): `target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver`
web.1: crashed 2013/06/27 22:04:16 (~ 4m ago)
and in the heroku logs:
2013-06-27T20:04:14.511136+00:00 app[web.1]: [error] play - ERROR: syntax error at or near "user"
2013-06-27T20:04:14.515578+00:00 app[web.1]: at play.api.db.evolutions.Evolutions$.databaseEvolutions(Evolutions.scala:334)
2013-06-27T20:04:14.515153+00:00 app[web.1]: #6emdb57b1: Database 'default' is in inconsistent state!
I tried to delete the whole db with
heroku pg:reset HEROKU_POSTGRESQL_ROSE_URL
and then i pushed again, but no success.
I have to mention that I did a push before, and at that time my app was running on Heroku. The only problem was, that i couldn't log in with the credentials provided in my fixtures (Global.java file with a job on app start).
Any suggestions?
From this error:
ERROR: syntax error at or near "user"
I guess your Evolution scripts are wrong. User is a reserved word in SQL. PLease try to run the Evolution scripts locally in a dev PostgreSQL database. Once working, you can try to deploy again.
I'd also suggest disabling evolutions for production apps, it's a risky system sometimes.
PostgreSQL interprets user as a keyword. If you have an app/models/User class in your app, play will try to create a table named user. The easiest way to avoid this is to rename your User class to something like MyUser. (The same might happen if you use an attribute named user in one of your classes. Here, as well, you should rename it).
Then you should run your application locally and open it in the browser in order to get the evolution script file updated. You can then find the evolution script at conf/evolutions/default/1.sql. According to this example, it should create a table named my_user now.