JHipster Spring Boot executable war config not recognized - gradle

I am trying to experiment with a JHipster 4.3 app using Hazelcast. I have a setup of 3 Linux/CentOS7 VMs, each with latest 8 131 java/jdk on them. I build my war file for -Pprod and deploy to a dir at:
/var/jhiphaze/jhiphaze-0.0.1-SNAPSHOT.war
I have set this up as a service using systemctl. I am able to start | restart | etc.
I now have a need to debug into the application and would like to start the app up in debug mode. I read in the Spring Boot docs that I can place a file of the same base name with the extension of ".conf" and Spring Boot executable script will read the settings in the conf and start the app up with that. So I have a file:
/var/jhiphaze/jhiphaze-0.0.1-SNAPSHOT.conf
with the following line:
JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
This has no effect on the run of the war, it starts up fine but does not listen and the console out indicates that the app is not listening on 8787 (or any port).
I also tried on my windows workstation, simply running from cli using:
java -jar jhiphaze-0.0.1-SNAPSHOT.war
in the project /build dir with the jhiphaze-0.0.1-SNAPSHOT.conf placed in the same directory. It is ignored there as well. The same argument in the conf file work at the cli:
java -jar -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y jhiphaze-0.0.1-SNAPSHOT.war
works fine, pauses and waits for me to connect. Note that I used suspend=n for most of my attempts as I did not want the service start to fail while waiting for debugger to connect.
How can I get the executable war to recognize its partner .conf file?

Related

How to run Spring Boot Application as a Service?

I have deployed my web application on company server by executing jar files then the project is running fine.But when i close the jar and again try to run the project on browser then client is not able to access the application.I want solution on this that if i close the jar then also client can access the application.
you can use this simple command to run a jar file as background service...
javaw -jar test.jar
after run this command you could not detect any change in cmd...and can close your command prompt. after 1 or 2 minute enter your URL in browser .. you will see your web program is running...
before run this command must be stop previously running jar for avoid same port conflict
for more details
When you close the cmd prompt, your java application will also be killed. To keep the java application running after closing the terminal you have to use the below command.
nohup java -jar app_name.jar &
just replace the app_name with your application name and run the command.

How to install Spring boot app on Ubuntu server?

I have Ubuntu server on Digital Ocean and I wrote Spring web app and now I want to put it in production.
I upload it via FTP to the server and I open my console via Putty and I use this command:
java -jar name.jar
Spring is started after that and when I open my web app everything is working fine, but when I close my Putty session my Spring web app does not work anymore. It seems like when I close my Putty session that also Spring web app is closed.
How to solve this?
While what KLHauser suggested will work, but if the vm is restarted in the cloud (which happens) your application will not automatically restart. Also stopping your application with kill -9 is error prone and dangerous, because you accidentally may kill the wrong process.
See running as Linux service section of Spring Boot documentation on how to do that.
If you’ve configured Spring Boot’s Maven or Gradle plugin to generate
a fully executable jar, and you’re not using a custom
embeddedLaunchScript, then your application can be used as an init.d
service. Simply symlink the jar to init.d to support the standard
start, stop, restart and status commands.
The script supports the following features:
Starts the services as the user that owns the jar file
Tracks
application’s PID using /var/run//.pid
Writes
console logs to /var/log/.log
Assuming that you have a Spring Boot application installed in
/var/myapp, to install a Spring Boot application as an init.d service
simply create a symlink:
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp Once installed,
you can start and stop the service in the usual way. For example, on a
Debian based system:
$ service myapp start
Just use java -jar name.jar & and the application is started in new process thread.
by adding also > log.txt directly at the end you would also have a log.

Intellij, Spring dev tools remote, Docker, error Unexpected 404 response uploading class files

Im trying to use Spring Boot Dev tools (Spring Remote), and automatically upload recompiled files to my docker container.
I keep receiving
Unexpected 404 response uploading class files
This is my docker file:
FROM java:8
WORKDIR /first
ADD ./build/libs/first.jar /first/first.jar
EXPOSE 8080
RUN bash -c 'touch /first/first.jar'
ENTRYPOINT ["java","-Dspring.data.mongodb.uri=mongodb://mongodb/micros", "-Djava.security.egd", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005","-jar", "first.jar"]
This is my configuration and the configuration
And this is the error I'm receiving:
As of Spring Boot 1.5.0, devtools defaults were changed to exclude the devtools from fat jars.
If you want to include them, you have to set the excludeDevtools flag to false.
However, the devtools documentation doesn't explain how to do this. The necessary documentation is actually in the spring-boot-gradle-plugin documentation.
To do it, you can put this snippet of code in your build.gradle file:
bootRepackage {
excludeDevtools = false
}
Unfortunately, this was buggy at first and had no effect as of Spring Boot 1.5.0. The workaround was to do this instead:
springBoot {
excludeDevtools = false
}
However, I have verified that the bootRepackage approach works for Spring Boot 1.5.8 .
I got the same issues as yours while using docker-compose to compose my application ( a web service + redis server + mongo server ).
As the Spring developer tools document point out "Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”."
I think when we running Spring Web Application inside Docker container, the developer tool is disabled then we cant remotely restart it.
Currently, I'm running my web application on the host machine and set the redis server, mongo server inside containers so I can restart the web app quickly when the code is changing in development process.
In my case I had to put the application context on the argument of the IDE RemoteSpringApplication configuration.
For example, my application root context was /virtue so I had to configure it like so:

Blank White Screen at localhost:8080 with Tomcat 8 on OSX 10.8.5

I followed this tutorial exactly: http://examples.javacodegeeks.com/enterprise-java/rest/jersey/jersey-hello-world-example/
But I just see a blank white screen when I go to: http://localhost:8080/JAXRS-HelloWorld/rest/helloWorldREST/JavaCodeGeeks?value=enjoy-REST
I started tomcat by running the command catalina run
Should I be doing something differently to deploy the webapp?
I have just tested the sample application on Tomcat 8 and it works without any issue.
As expected it prints out the below message in the browser when called.
"Hello from: JavaCodeGeeks : enjoy-REST"
There are couple of things that I can think of might causing the problems in your case.
You are missing any of the steps specified in the tutorial.
You are not deploying the "JAXRS-HelloWorld.war" into Tomcat properly.
I hope have setup your CATALINA_HOME properly in order to call the "catalina run" in commadline.
To resolve your problems.
Instead of following the steps in the tutorial, download the attached project and generate the war file as specified and deploy it and see if it works.
To deploy the project in tomcat, you have to copy the "JAXRS-HelloWorld.war" file into $CATALINA_BASE/webapps folder and then start the server.
There are couple of ways to start the Tomcat server. One that you have chosen is the commandlne. To start the Tomcat server from caommandline either you have to change directory(cd $CATALINA_BASE/bin) to Tomcat home bin folder and the call catalina.bat/catalina.sh with run or start command Or set the CATALINA_HOME enviorenment variable and then call the same command from anywhere in your commandline.
Note:
Also check the Tomcat logs for specific issues or errors.

auto start stop remote tomcat before redeploying war by jenkins (deploy plugin)

at the moment jenkins build my project and at the end the artifact is deployed on a remote tomcat via jenkins deploy plugin.
the problem is that after several redeployments this process fails (sometimes tomcat hangs or (un)deployment fails). in all cases stopping tomcat and manually undeploying helps.
Is there a way to stop tomcat before building/deploying, delete the old war and appfolder, and restart tomcat before deploy plugin wants to deploy the artifact?
thx in advance
You could write a batch file that does all the things mentioned:
stop tomcat
delete war files
start tomcat again
Then you can add a new pre/post build task in job configuration as execute batch and simply point it to run your batch file.
Added:
You can use PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553 It allows you to run processes remotely. Put batch on remote machine and from local one using Jenkins run sth like this: PsExec.exe \xx.xx.x.x C:\MyScript.bat
one addition to accepted answer:
it is important to reroute the output and error output of PsExec call (took me 2 days of debugging). See http://jenkins.361315.n4.nabble.com/remotely-executing-commands-td3476417.html
it seems that if called from java (like jenkins/tomcat) or .net PsExec hangs or quits with error. so the call should look like:
c:\someBatchWithPsExec.bat >>log.txt>&1
or explicitly on every call:
PsExec.exe -u [domain\remoteuser] -p [password] /accepteula \remoteMachine net [stop|start] Tomcat7 >>log.txt>&1
i guess if jenkins runs with domain\user u don't have to mention it in command?! (just tried it but it didn't work - the net commands fail)

Resources