Mount Java app inside cucumber rails app - java

I have a rails app that talks to an api running on the same domain via ajax calls. I want to test this app using cucumber. The api is written in java and packaged as a jar. How can I mount the jar when using cucumber?

There is no way to do it automatically but you can add Before hook into env.rb or put it into separate file and in this method you can load your java extension by issuing shell command, you can store process pid in variable and kill this process in After callbalk. You can configure Capybara to start server on specific port and I think you can tune your application to use specific port too.

Related

Start java application after a crash or server restart

I have a few Java applications, mostly with Spring Boot, in different servers (Droplets) from Digital Ocean. Previously I upload each new release manually and with some shell scripts created I am able to start/stop the applications. These scripts contains environment variables when it's necessary for test or production environments. To check if the application is running I have a cronjob launched every 5 minutes, this cronjob execute a shell script to start the application if it's not running.
However I switched to automatic deployments using Bitbucket pipelines and now I won't have shell scripts anymore because all the configuration will provided by the Bitbucket pipeline and will be executed over SSH.
For instance cat environment.sh start.sh | ssh xxx#yyy where environment.sh is created on the fly by the pipeline with right configuration in that moment for each environment.
How can I do something to start the application automatically if it's not running? Should I upload the script files in each automatic deployment and use a cronjob?
You should use a wrapper. YAJSW is popular, free and works (in my experience) well in production systems. The wrapper will restart your process if it crashes and can easily be installed as a service over many different OSes without much effort.
NOTE: I am not affiliated or related in any way to YAJSW.

Using Java Spring, Is it possible to run a service that execute on the client side?

I want to create a simple strict service that tells the client if a PDF file is searchable or scanned images (not OCRed). Then I thought that the code is very simple and could run very fast, but the heavy lifting is in uploading the file especially if the file is large. Is there a way in Java and Spring to execute the code on the client's machine (if the client has JVM) by sending the code to the client to be executed and get the result?
Are you looking for Java Web Start?
https://www.java.com/en/download/faq/java_webstart.xml
The Java Web Start software allows you to download and run Java
applications from the web. The Java Web Start software:
Provides an easy, one-click activation of applications
Guarantees that you are always running the latest version of the application
Eliminates complicated installation or upgrade procedures
A signed Web Start application can request permissions to access local resources, native libraries and hardware.
To send the result back to server, you can simply have the Web Start application send it via HTTP[S]. The JNLP used to launch the Web Start application can be dynamically generated, so you can set parameters for the Web Start application, to have it send the parameter back to server, so you can identify which user session it is.

Can Java Web Start be used to run server-side programs?

I have a Java application that needs to run the proprietary software PowerWorld on the server and then return output to the client side Web Start window. Is this possible? How do I go about doing this?
I am using Apache Tomcat to run the server. My Java code uses Runtime.exec() to run a Python script that runs PowerWorld. I made sure that the python script, powerworld file and java app are all in the same directory and reference each other using relative file paths
Java WebStart will install a desktop application into the cache of the client. That will run on the client not on the server, however you can easily create a webapplication as a service, i.e. on Tomcat. The webapp will be able to receive client requests, i.e. via RMI, RESTfull service or webservice, call the proprietary programm and return the results.

how to run java application on aws instance using command line

I now have a java program and amazon instance provided with a key..
Used to run java on aws programmatically, but now all I need to do is, use this instance, powerful.. to run my java application, but how.?
Should I make my java program a .jar and upload on the instance?
And documents about the command needed?
Thanks.
You upload a file to your EC2 instance with scp:
scp your.jar root#your.ec2:/tmp
You run your file with ssh:
ssh your.ec2 "java -jar /tmp/your.jar"
All that can be easily automated since no passwords are required to execute scp or ssh, you'll just need to exchange certificates.
Or did you mean that you wanted to make Java program part of your image?
If your Java application is web based, I would encourage you to have a look at Amazon's Elastic Beanstalk
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Java.html
This service allows you to quickly deploy and manage applications to the cloud without worrying about the underlying infrastructure.
See more at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Java.html
Seb

Call to remote JVM using cmd script

I need to call a jar which is kept on a shared windows machine.
The JVM also needs to be placed on this shared machine so that anyone with access to the remote location should be able to call this jar.
I need to write a windows script which shall be run using a service user.
Is this possible? If yes, request you to please provide pointers.
Java Management Extensions provides the tools for building Web-based, distributed, dynamic and modular solutions for managing and monitoring devices, applications, and service-driven networks.
see JMX Tutorial
see example with Linux script
see Windows cmd script
You might have some luck using the Tanuki Software Java Service Wrapper. Jetty uses this for their Windows Service Wrapper.
Another option is Apache Commons Procrun, which is what Apache Tomcat uses.
Both work well to set up a Java application as a Windows service. You will need to ensure your application is designed to run well as a service; you should be able to "trigger" events (start, stop, restart, etc.). You might need a lightweight adapter around the application to get it to work right as a service; but that should be a trivial exercise.
Once you have a service set up, make sure appropriate user(s) have rights to start/stop the service [1] [2]. You could even set the service up to run using a specific account. Then you can use the net start, net stop, etc. commands in a batch file.

Categories