Deploy a JAR file to a VPS server (Ubuntu Server 16.04) - java

I need to deploy my spring boot rest api to my VPS server, to do so I installed JAVA and MAVEN. I ran it using sudo java -jar myfile.jar it is working but the problem is that after sometimes it stops and my webservice send me error 503.
I would like to know how to deploy it and run without it stopping.
PS : There is no page ".html" to be accessed that's the reason I want to deploy as JAR

Related

Can not run jar file on websphere

I had problem with Websphere.
I want to run test.jar in websphere.
I copy test.jar in dropins and run "sh ./server start --archive="java -jar ../dropins/test.jar"
Starting server --> ok
But console.log empty
It's not clear from your description exactly what you're trying to do, but based on your title, I assume you're trying to run a Java application. Liberty is an app server for running Java EE apps, but given that you're trying to run a file ending in .jar, that is more typical of a standalone (Java SE) app. Also, the command line you're using is mixing options, the --archive option is for specifying a target file for the server package or dump operation. See the IBM help topic https://www.ibm.com/docs/en/was-liberty/base?topic=line-server-command-options for more details. On the Liberty app server, you can deploy Java EE (not Java SE) apps by copying the .ear or .war of the app to the dropins directory. If you provide additional details about the contents of test.jar and what you're trying to achieve, you'll get a more complete answer.

How can I deploy a java web app to heroku?

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.

How do I remove jar filename before endpoint's url?

When I compile my maven-based project I have the resulting jar file in 'target/my-application'. When I run locally my application (I use Payara Micro if this is important) I have the following in log:
Payara Micro URLs
http://localhost:8080/my-application-1.0-SNAPSHOT
How do I get rid of my-application-1.0-SNAPSHOT from URL address?
As per request, I'd say that:
What type of application is that? EAR/WAR?
war application (however, maven creates for me "payara-uber-jar"
and I run the application via java -jar filename.jar
What application server is it running on?
Payara micro
Are you using maven?
Yes, I am.
Hello according to Paraya documentation what you need to do is:
java -jar payara-micro.jar --deploy NAMETHATYOUWANT.war
And then the context path will be /NAMETHATYOUWANT
https://www.davidsalter.co.uk/payara-micro-context-path/

Running jar as a Windows service with nssm

I am trying to run a jar (spring app) as a Windows service. I am using nssm to do so.
When I run the jar file with java -jar myjar.jar everything works fine. My webapp responds when I enter localhost:8080 where it runs.
After I run
nssm install MyService java -jar myjar.jar
nssm start MyService
I get in the console: MyService: START: The operation completed successfully
My application is usually logging to file as well, but it does not do so when running as a service. It seems like the application is not starting at all. When I try to access localhost:8080, nothing is responding.
Why isn't my app running when I start it as a service with nssm?

Can a java .war file contain a webserver

I'm looking into installing Jenkins, in the instructions it says
"Easy installation: Just java -jar jenkins.war, or deploy it in a
servlet container. No additional install, no database."
I understand the servlet container method, but does the above statement mean that just installing Java and running the .war file will somehow spinup a webserver and start serving http request ?
Yes, the war file contains the built-in Winstone servlet container, and running that command will start it and make it listen for requests on port 8080.
Edit: Jenkins 1.535 and above bundles Jetty (rather than Winstone). You can still run it with java -jar jenkins.war.
Jenkins comes bundled with Winstone, a very lightweight servlet container. As such, Jenkins can be started from the command line as stated by the instructions without any additional software installation.

Categories

Resources