I can't open my app in Heroku - I get error H10. When I run my app in Eclipse or use executable jar file - everything work well. Here is my code : GITHub Below is my log file:
DropBox
You app is running on port 8080, but on Heroku it needs to bind to the environment variable $PORT. You can fix Spring to do this by adding the following to your application.properties:
server.port=${PORT:8080}
This will use $PORT if it's set, and default to 8080 if it's not.
I solved this error using Procfile, the Procfile is always a simple text file that is named Procfile without a file extension, For example, Procfile.txt is not valid, The Procfile must live in your app’s root directory. It does not function if placed anywhere else.
What to write in Procfile?
web: java -jar build/libs/your-project-name-version.jar
the version you can find inside build.gradle/pom.xml
Example:- web: java -jar build/libs/khatabook-1.0.jar
Where to create Procfile?
I have given my project structure image link for
[1]: https://i.stack.imgur.com/tsB35.png
My gradle file link
https://github.com/himanshujainpro/khatabook/blob/master/build.gradle
My application.properties
https://github.com/himanshujainpro/khatabook/blob/master/src/main/resources/application.properties
Project link for further reference
https://github.com/himanshujainpro/khatabook
Related
I have a simple Springboot app that can be ran with the command: ./mvnw spring-boot:run. This works fine if I put the URI to my database inside of the application.properties file but the problem is that this file is used by Heroku, and is not meant for my local use.
So I came across a Stackoverflow answer that said I could simply make another .properties file but name it application-dev.properties and then when I run my app, the correct .properties file will automatically be chosen when I set the active profile to dev.
So I tried this by doing the following:
Make the application.properties file use the environment variable from Heroku since this is the .properties file I do NOT want to use locally.
I created a .properties file called application-dev.properties that has this line in it:
spring.data.mongodb.uri=mongodb+srv://MY_NAME:MY_PASSWORD#springbootcluster.v1maw.mongodb.net/Employees?retryWrites=true&w=majority
I run the app like this: ./mvnw spring-boot:run -Dspring.profiles.active=dev
The app fails with a ton of different errors because it is trying to use the application.properties file and not the application-dev.properties file
Part of the error message:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'employeeRepo';
ERROR MESSAGES
-Dspring.profiles.active is setting the spring.profiles.active system property in the JVM that's running Maven, not the JVM that's running your application. To fix the problem, use the spring-boot.run.jvmArguments system property to configure the arguments of the JVM that is used to run your application:
./mwnw -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"
Alternatively, there's a property specifically for setting the active profiles which is slightly more concise:
./mvnw spring-boot:run -Dspring-boot.run.profiles=dev
You can learn more in the relevant section of the reference documentation for Spring Boot's Maven plugin.
I am running a java spring boot application as jar file with DCEVM hot-swap agent. When i change some class files in my jar file the application is not reloading those changes. But If I extract my jar file and run my application as a simple java class file adding all dependencies to class path( like how IntelliJ Idea does) then replace any of the class file it reloads successfully.
Running extracted jar file:
java -XXaltjvm=dcevm -javaagent:path/hot-swap/hotswap-agent-1.3.1-SNAPSHOT.jar=autoHotswap=true -Dspring.profiles.active=local -Dserver.port=8082 -classpath path/jdk1.8.0_191.jdk/Contents/Home/jre/lib/charsets.jar:--jdk-lib-jars:./path/classes:..other-jar-file-path com.company.app.App
after running above command if I am making any changes and recompiling and then replacing updated class file then the changes are detected and my app reflects the changes.
HOTSWAP AGENT: 15:35:55.349 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [com.company.controller.HealthController] (autoHotswap)
I get above log which tells me that class is reloaded. everything works fine.
Running jar file:
java -XXaltjvm=dcevm -javaagent:path/hot-swap/hotswap-agent-1.3.1-SNAPSHOT.jar=autoHotswap=true -Dspring.profiles.active=local -Dserver.port=8081 -jar app.jar
After running If I update the jar file with following command:
jar uf app.jar path/HealthController.class
jar file gets updated but changes does not reflect and there is no log generated.
HotswapAgent does not detect class modification inside jar file. Instead of it you can use extraClasspath config param. Look at http://hotswapagent.org/mydoc_configuration.html how to setup it.
I am not able to run a spring boot application (main class) from UNIX using putty with could not find or load main class error.
All files are given 0755 executable permissions under the project folder. Tried using command:
java -cp .:batch-services.jar:lib/* com.spring.integration.demo.SpringBootDemoApplication
Running command from the path: /app/batch
Folder structure in UNIX:
/app/batch/lib - this folder has all the dependency jars
/app/batch/batch-services.jar
Expected result is that the spring boot application will start successfully.
Actual result is:
Error: Could not find or load main class com.spring.integration.demo.SpringBootDemoApplication
It looks like you have encountered a common issue with how Java interacts with shell wildcards (asterisks). Java expects your classpath elements to be separated by colons, but your shell generates spaces.
The solution is to quote the argument. See this answer: Including all the jars in a directory within the Java classpath
Also, if you are using spring-boot, you can build your application into a so called fat-jar.
Have a Spring Boot (1.5.4.RELEASE) based microservice which I deploy a jar to an AWS EC Instance (Linux environment). Now, I am also deploying an external log4j.properties file so I have to start the microservice like this:
java -jar myapp.jar -Dlogging.config=/path/to/log4j.properties
How can I configure this Spring Boot Microservice as a Linux service where I can start and stop it using these flags:
sudo service myapp start | stop | status | restart
Thank you very much.
Using a symbolic link to your springboot app you can make it controllable as service...
sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
Placing an application.properties into your myapp folder you can override the one bundled inside your app. This way you don't need to use command line switches. Simply specify the path to your log configuration as value to property key logging.config inside of it.
NOTE, though, that this solution is not really best practice. Once you're running a whole bunch of services in production, you probably rather want to go for something along the lines of spring cloud config for externalizing configuration and you probably also want your logs aggregated at a centralized service that allows for an overview of all your services' logs in one place.
As per spring-boot deployment,
A fully executable jar can be executed like any other executable binary or it can be registered with init.d or systemd
Make sure you build your app using the plug-in below (gradle version in shared link):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
and as shown by Jörg, create a symbolic link inside init.d:
sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
That is the simplified version :)
More to your question, you need to customize the init and this can be done by a conf file - all specified in the documentation.
With the exception of JARFILE and APP_NAME, the settings can be
configured using a .conf file. The file is expected next to the jar
file and have the same name but suffixed with .conf rather than .jar.
For example, a jar named /var/myapp/myapp.jar will use the
configuration file named /var/myapp/myapp.conf.
such as:
myapp.conf
JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder
I have a node app which contains a node plugin that references a jar file. My question is this -
Is there a specific example of a heroku multi buildpack which loads all three -
...nginx.git
...java.git
...nodejs.git
In my root I have the following:
.buildpacks
.nginx
system.properties
package.json
Also, if this is a native nodejs app that is dependant upon a plugin which refrences a jar file and hence need to load the java environment, is it necessary that I also include a POM.XML file in my application's root?
Instead of the Java buildpack, use the jvm-common buildpack. This way, you won't need a pom.xml. You can put this line in your .buildpacks file:
https://github.com/heroku/heroku-buildpack-jvm-common
Or set it with the heroku buildpacks command.