Using a Java program I made on a Web Server - java

I created a small application that, when run, creates or updates some tables in a database by extracting data from some PDF files. Everything works fine in this desktop application, but the next step for me would be to make it possible for an administrator on a website to upload a PDF file and my Java program would then run and update the tables accordingly.
The problem is I have no idea where to start with this (the site isn't done yet, but I'm running some tests and it is going to be coded in PHP). I'd like to know what kind of technologies I need to let the server run the program and update everything as it would in the offline version. Sometimes it takes a while to update everything, so ideally, the user uploading the PDF could continue browsing other pages while the server does its job. (I'll probably implement something that when the server is done processing the file, it says if the program ended successfully or not in a log file)
Can someone tell me what terms to search for on Google or give me some pointers? I haven't chosen where my website is going to be hosted either, so if someone could tell me what to look for to know if they support running applications like this, I'd really appreciate it as well!
This could also apply to other programming languages as I know a bit of Python and C++ as well, so in the future I might have some applications in those languages I'll want to use on the web.
If I'm not approaching this the right way, I'm open to other suggestions, but the best solution would be to keep my Java program intact as I know it works exactly like I want it to and I'd rather not have to start it all over again.

If your host is *NIX based you can use crontab (Automatic Task Scheduler) to run your program at set intervals. Make it check if a "new" PDF exists, and run the program if there is. There may be a way to use Windows Task Scheduler type programs to do it on Windows. This is probably the easiest way.
Alternately you can use You can use shell_exec() in your php to execute a command on your *NIX system directly to run your java program.

Related

Is it possible to build a web automation that can run through a browser?

I have created a Java program that utilizes Chrome Driver, Selenium, and Java Excel API. The program is used to automate a few different processes on Google Chrome. Currently, setting up this automation is more complicated than I would like it to be: the user needs to download a zipped folder, unzip it, download the Java Runtime Environment, and launch the program using the executable.
My goal is to simplify the installation of the automation. Ideally, a user would come to a SharePoint website, fill out a form with the parameters of the automation (potentially upload an Excel Workbook), click an "execute" button, and the automation would run. As a result, the automation would run seamlessly across platforms (Windows and MacOS) without any modifications.
I have researched changing the programming language to achieve this functionality. I concluded that a different language could remove the need for a Java Runtime Environment download, but it would still require some type of installation process. Additionally, I have researched using HTML/JavaScript, but I concluded that this is not possible because the functionality (triggering a web automation from a website) could be used maliciously without the user's knowledge. Finally, I began researching containerization through Docker. This solution seems promising but I do not know enough about it to determine if it is the appropriate solution.
What would be the best route to achieve the results that I am looking for (outlined in the second paragraph)? I have access to enterprise-grade databases that I thought may be useful. Would it be possible to have the form trigger a virtual machine to run the automation on a remote database and then output the result to the user once it has finished?
Thank you in advance for any guidance you can provide. I do not know much about making a Java program into an enterprise-grade application so any information about what to research is extremely useful. Finally, please do not hesitate to correct my logic at any point in this question as I may have drawn the wrong conclusions from my research.
You want to look into creating a jar file with your selenium code.

Best way to execute java program on server

I need to execute a java simulation program for a very long time, many hours or maybe days, and i wish i could do it on a server.
I've been heard about Cloud Computing, and i'm searching a free platform, or a very cheap one.
For example, i found Oracle Cloud, but i am open to any type of solution.
On the link there are several points to follow to deploy an application, it seems a bit complicated and you also have to install Maven.
Do you think there is a simpler solution, or that this one could be my best try?
I mean, my program consists on a few .class files, i wish i could edit/compile/run the main class very easily, like with a kind of shell or cmd.
Unfortunately, i know very little about web programming, so i don't know even if this would be possible.
However, assuming i can launch my program, and log in after a very long time, will i be able to read the results?
Or is it possible to write a text file to read the results later?
i wish i could do it on a server. I've been heard about Cloud Computing
A possible solution is using AWS Lambda. You only provide your Java code in a ZIP file and it will run in a "server-less" environment. What this means is that you don't have to setup a server yourself instead AWS will manage everything for you.
i'm searching a free platform, or a very cheap one.
It's not for free, but it's pretty cheap though: https://aws.amazon.com/lambda/pricing/
However, assuming i can launch my program, and log in after a very long time, will i be able to read the results? Or is it possible to write a text file to read the results later?
I would not recommend writing it to a text file, instead look at solutions such as S3 Buckets or Elasticsearch with Kibana

Moving files from Tomcat Linux to another Linux Server

I've taken a job where years ago their webmaster setup an intranet using Tomcat on a linux server. The users can create something in the test environment and then click "make live" and the Linux/Tomcat moves the file to a Linux/live PHP web setup.
I'm clueless how they're moving the files. What would be a common tool to do this in Tomcat and Java?
I realize this is vague, but any help would be appreciated. Let me know what other info would be needed.
Also there is a duplicate MySQL database in both servers. I'm guessing the Tomcat setup is writing duplicate info to both databases, but I don't see how the files are getting moved.
This sounds like the website content is completely stored in the database and written over to the other server.
Theoretically you could also have a rsync shell script and call that from php to actually synchronize files over to the other server.
If the "Make Live" is on click and happens immediately its either a direct db access or some script based synchronization.
If it takes a while it could be a cron-job. Maybe you should just check this anway crontab -l will work.
There are several options, you actually open the *.php which the user can edit the content and see where the make live button brings you e.g. "Post Form to *.php" and than you check what that script is doing or you show us the package (what i would like to see but not suggest if you are working on a companies site).
Get back here with some more information, so i can expand the answer for you. Maybe you should also clarify why you are clueless, state what you have checked already, the info i would require is the actual site which has the make live button on it, it will lead to the next site or a script which will probably show what the site is doing.

I want to check open applications before turn off my computer through java program

Actually I am working on a java based application which has a functionality to turn off my system on a specific time and it's working fine but, the requirement says that if any application is open then it should not be close before turn off my system must have to close all the open application manually.
I am unable to find out the solution.
I have never tried this but it looks like you would have to use: Runtime.getRuntime().exec(). This seems to be a pretty good example of how to do this.
Java JNI
https://github.com/twall/jna/
Get the list of all processes via WinAPI and check for user_name in PEB of a process.
Or this http://msdn.microsoft.com/en-us/library/aa390460(v=vs.85).aspx :)

Advice on which language to use

I'm trying to create a web application which will get input from system.
What this application should do is to listen what happens when some shell scripts are executing and reporting the status trough web.
An example :
I'm copying thousands of records with shell script, and while this is still executing I'd like pass the current status of the script to the web interface. From shell script side I could echo something like "The files are being copied please wait for it to finnish".
Using which programming language from shell side would be the easiest way to pass this to the web interface? I intended to use JSP/JAVA for web.
Is this even the right way to think about this? Every suggestion is welcome
EDIT
Would something like http://nodejs.org/ be useful for this?
I'd use a named pipe (FIFO) instead. You simply write your output to the pipe and let the application read it. I'm not sure if there is any other way to get a more live system than this.
I'd recommend Perl as the back-end.
EDIT:
named pipes are a special type of files on UNIX. The abbreviation FIFO stands for "First In First Out". On LINUX Journal you can find an interesting read about named pipes.
Perl is a very powerful scripting language with many ready-to-use modules which you can find on http://cpan.org. You can find some answers here on SO about how/where to start learning Perl.
The Web part of your application can easily read a file or a database, so you just need to make sure that your shell scripts are outputting something for your Java code to update.
For example, if you run your shell script like this
./myscript.sh > mylog.log
Then in your Java code (note that you should not have logic in your JSP), you can read in the file to determine the status of the update, and output the result to your JSP.
It would be better to read the data in from a database, but that would involve you changing your shell script to output the data to a database.
You could put shell script output to some storage on server. And use AJAX on the web page to poll the server and get updates from that storage to the page.
If you will decide to use JSF for web page creation I can recommend "a4j:poll" component from ajax2jsf library. It is very simple and straightforward. Very easy way to poll server from the web page.
Writing to log file would be the simplest solution. And in programming, simple often means good.
If you really need very fast/realtime system, you should probably make these logs a database.
As for language, use what you like best. They all do support SQLite, including bash.
If I understand your question correctly you want to display a web page on a client machine that reports the status of a long running task on a server machine. If that is the case then you need to focus on something called AJAX IMO.
For what it is worth the simplest and easiest to understand implementation of AJAX that I know of is Apache Wicket.

Categories