I've a java web application and I want to install node server in the background so I can execute js files from java in Heroku.
I want to execute node myFile.js
Add the Node.js buildpack to you app by running:
$ heroku buildpacks:add heroku/nodejs
And make sure you have a package.json file in your app.
Related
I have a Java web app with Tomcat embedded in my jar file. I can containerize the app with Docker and run it with command java -jar -myapp.jar, but I can't run that container in Heroku. I tried using heroku CLI to dockerize and deploy, but Heroku gives me an error of "can't access jarfile".
I tried to fix this by using heroku deploy:jar to deploy my fat jar, but this erroneously gives me an error:
heroku deploy:jar target/*.jar -a medscanner2
-----> Packaging application...
- app: medscanner2
- including: target/medscanner2.jar
! ERROR: Could not get API key! Please install the Heroku CLI and run
`heroku login` or set the HEROKU_API_KEY environment variable.
! Re-run with HEROKU_DEBUG=1 for more info.
!There was a problem deploying to medscanner2.
!Make sure you have permission to deploy by running: heroku apps:info -a
medscanner2
I am signed into Heroku and I can use heroku auth:whoami to verify that, I can push containers and deploy them, so this error doesn't make any sense. I reran with HEROKU_DEBUG=1 and it did not return any more info.
I further tried to set the HEROKU_API_KEY variable in the CLI with a token I got from Heroku and this still caused the same error when I try to deploy the jar.
I am using a Procfile (although I am not sure it is necessary):
web: java -Dserver.port=$PORT -jar target/medscanner2.jar
Since the issue seems to be indicating there is an issue with access I don't see how the Procfile could be influencing it.
What is the best way for me to deploy a Java web app that does not using Spring Boot to Heroku? I have separately deployed the docker container successfully to Google app engine, so all this work for Heroku is very frustrating.
I ended up fixing this by using webapp-runner to deploy my app. It runs the webapp-runner jar which can run your .war files. This required adding the heroku-maven-plugin and maven-dependency-plugin.
I could then add a Procfile: web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT
and use the Heroku CLI to add the app using git. The link with webapp-runner is a guide to deploying tomcat java apps with webapp-runner.
I'm looking for a way to run Heroku CLI commands within a java application hosted on Heroku.
I'd like to be able to run commands like heroku pg:backup heroku pg:restore etc
Is there a way to do that ?
EDIT : I added the Heroku CLI to my app, now I'm looking for a way to invoke heroku commands from my java code.
Maybe you could use something like this :
ProcessBuilder pb = new ProcessBuilder("/path/to/herokuCLI", "myCommand");
Problem is I don't know how to find the right path.
If you look at the file structure of your app on Heroku you can only find your .war + some "configuration files" which is quite normal as you only push a war to Heroku : Procfile system.properties target
Besides I don't think that's the right way to do that.
I'd like to avoid doing backup/restore operations in pure java code.
Maybe you can't rely on Heroku cmd to do the job for you after all.
You'll need to add the Heroku CLI buildpack to your application. You can do so with: heroku buildpacks:add heroku-community/cli
Push a new build after you've done so and you'll now be able to run CLI commands from inside your application dynos. You can see some additional information about this in the documentation.
I am new to Heroku. The backend logic of my flask web app is actually running a Java subprocess (subprocess.call( ...) ) to get some helper data. (I know it's a bad thing to do)
On deployment, Heroku works as expected and installs Python runtime and frameworks from requirements.txt but not JDK.
Any way I can configure Java in the same and make this work ??
Run the following command:
$ heroku buildpacks:add heroku/jvm
Then redeploy with a git push heroku master. This will install the JDK into your slug.
I was trying to build a JAVA web application using Docker. I was making a docker container to deploy and run the application. I am beginner. So I started with small POC for java application(jar) which was working fine. I made some changes for JAVA web application(war) and created a Dockerfile for the project which is as follows :
Dockerfile
---------------------------------------------------
FROM java:8
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /code
ADD pom.xml /code/pom.xml
ADD src/main/webapp/WEB-INF/web.xml /codes/rc/main/webapp/WEB-INF/web.xml
RUN ["mvn", "dependency:resolve"]
ADD src /code/src
RUN ["mvn", "package"]
CMD ["usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-war", "target/techpoint.war"]
----------------------------------------------------
Build was successful but when I run the application - It says
"Unrecognized option: -war | Error: Could not create the Java Virtual Machine | Error: A fatal exception has occurred. Program will exit"
And when I replaced "-war" with "-jar" - It says "no main manifest attribute, in target/myapp.war"
Can somebody tell me how can I make JAVA web application (war) compatible with Docker deployment process. That means what should be the actual Dockerfile (with commands) to make possible to build and run the application?
You need a web server or an application server container like tomcat or Jboss (and many others) to deploy and run your java based web application. Your "techpoint.war" files need to be copied to the specific folder depends on each web server. For example, if you are using Tomcat then you can copy it to the /webapps folder. Tomcat will extract and deploy the war file.
You can add the following to your DockerFile.
FROM tomcat:8.5.11-jre8
COPY /<war_file_location>/techpoint.war /usr/local/tomcat/webapps/techpoint.war
You can build the image using docker build command and start the container from the created image.
docker build -t techpoint.
docker run -it --rm -p 8091:8080 techpoint
Now Tomcat will extract and deploy your war file.How to access the deployed application depends on the webroot of your application. For example,
http://<ip_address>:8091/techpoint/index.html
I would like to setup a Docker container using the following image: https://github.com/heroku/stack-images
I have installed the image inside Docker using
docker pull heroku/cedar:14
Which steps are required to start a Docker container that works in the same way Heroku does?
Communicate via Heroku ToolBelt cli in order to start and scale the application
Deploy applications using git and build using Java BuildPack
I've found an approach where you can turn an Heroku application into a Docker container but it is not the solution i'm looking for:
http://www.centurylinklabs.com/heroku-on-docker/
Checkout the Dokku project. It utilizes a docker project called buildstep to run Heroku buildpacks in a Cedar-like environment.
Have fun!