Automating Scheduled Task- Running main.java file - java

Daily i run a job in eclipse its batch job every day 11 pm. It's a main.java file need to run java application once executed i have copy the console output log into a notepad and i save with name as log file(exmaple.log), this file has to be posted to the particular share point portal, and an automated mail should be shared to the group about the file.
I want to automate this process. Please help me out, i am new to this process, but trying to automate the process which manually executing daily basis.

Since you added shell and cron, i am assuming it's kind of unix.
Verify server got connectivity to SharePoint server and mailx is enabled. If it's present you can do everything from server itself. This will be my approach.
Modify code
To log the required data to a file. You can either use a simple file
writer or use logging libraries.
Upload file to share point using share point rest api. Java httpclient can be used to execute http requests.
Use javax mail to send email. Or use native mailx unix command.
Convert java class to jar file. Schedule as cron job.
If you don't have connectivity. We have to do everything from local machine.
In that case, code should be modified to connect to server and execute remotely over ssh. Use cron or windows schedules for job management.

Related

.bat file not running when executed by app as windows service

So, I have this client-server app which is written in 4th Dimension Language, that runs as a service so it restarts automatically if something happens to the server. This language has a built in function which allows you to run cmd commands and I have another java app in the same folder, that is in charge of sending emails, something my server side app cant handle. We use a command for running this jar from cmd and send the parameters from there, creating and xml for it to create an html from that and send it via email. The thing is when I run this command with the app running as a service, the command simply does not run, but, if I run the app normally, it works like charm, with no problems whatsoever.
At first I thought it could be the paths, so I got all the paths to be absolute, using the full route, yet it doesnt work still. Also I tried exporting the command as a bat and running it by hand, in the exact same path were the server is, and it works just fine. I thought that maybe the service needs some sort of admin privileges, so I started it as Admin from the service, but it changed nothing.
Is there any chance the service has some sort of limitation which doesnt allow the app to execute external commands? If so, is there anyway to bypass this limitation?
Well, I couldn't make it work when it was running by service, so I made a bat with the command the service uses and pasted it in the Windows Startup Folder, so it "opens manually" when windows starts. It's not the real answer, but is workaround for needing to use the service.

Upload and Download File over Remote Node without Input Tag as File type

I am Automating a Scenario for Web Application Over Windows which includes the File And Images to be Uploaded to a website, and on my local it is working fine through robot class **
but when i execute my tests over Jenkins my jobs get failed. I need to Upload my file to a web site executing over Remote machine.
**
For File Upload :-
I cannot simply upload the file using send keys method since The Input tag doesn't have File Type i.e. input[type!='file'].
Are there any other solutions to achieve this without using Robot Classes and Auto-It.
**
For File Download:-
**
And I also need to download the File from a web Application over remote and verify that it has been downloaded successfully provided there is no API for this.
When the file gets downloaded over the remote, I am not able to verify that whether it has been downloaded or not since Remote Machine execution is not visible.
Is there any way to achieve this, kindly please suggest.
As you are using remote desktop for execution of scripts which would fail robot class action calls as it needs screen to be unlocked.
For the better results try using AutoIt is a free ware tools used for such purposes.
AutoIt will identify browse file objects and perform actions on it as Selenium does on Web applications.
Identify the Windows control, through AutoItV3 Windows Info tool.
More detailed steps to use AutoIt is present in the below link:
https://www.softwaretestinghelp.com/autoit-tutorial-to-download-write-autoit-script/
Thanks and regards,
Sandeep Jaju

Can batch files execute (local) Java code from a local machine to a remote machine

Background: I am trying to run some Java code on a few target machines (to check registry values using JNA) and I don't want to have to install Java on every machine I need to check. I thought that a possible solution was having the server running the Java app use a batch file that lives on the local server. This batch file would simply call a Java program and get the data I needed from the remote machines.
Question: I have a local batch file that I am executing using Java. This batch file will remote execute on target machines. The batch file calls/runs a Java program. Is it possible for that Java program to live on the main server or does it need to live on the target machines as well?
if understood right, you could just say to the batch file to print a report of registry info that you are searching, then use java to directly reach that report, and then you could "analyze" that code in your "server"
with this you don't need to have java installed on local machine, and you don't need to launch "application" but simply: a script.

Running a Web Service without opening Eclipse or any IDE

I want to develop a Java based Webservice on my laptop. This webservice will take one input parameter, query my SQL Server database and will fetch information and will return it back.
I know, I do not need a webservice here. But, right now, I am just testing my android application which will call this webservice and will show return data on my device.
So, I have developed a java program which connects my SQL Server Database (which is present on my laptop) and returns a value against the parameter passed. I have made it a webservice by creating endpoints and publishing it from another class.
For reference, something like answer on this thread
So, when I run it from my Eclipse, I can go to a browser and run my webservice, pass parameter and get result.
But, once I close my eclipse, its no more accessible. I am new to this and after studying I am guessing that I will need IIS to host it on my laptop.
I want to ask, whether it is possible to run/publish it locally on my laptop as a background process so that I can test my android app by calling the same?
Future scope -
I am going to deploy this webservice in my company which will connect my database. Both webservice and sql server will be on same machine. I am going to call this webservice remotely over internet from my android device to show the results.
I guess, I will need IIS in future right? Is there any other way to fulfill this requirement? Please provide some ideas.
If, within Eclipse, you can get your web application deployed so that it is accessible via a browser, then you definately can do it without eclipse.
Eclipse uses plugins like Tomcat or Glassfish to run your webserver. These programs are available outside of Eclipse as standalone services. You can install these and run them as background processes at the command line.
Just figure out which one you are using in eclipse (or which one you want to use) and look for a standalone copy on the web.
Here's Tomcat, btw.
I am done with this.
What I did is, I went to Eclipse, selected my Project-> Right Click -> Export -> Under General -> Ant Buildfiles
This created, Build.xml in my Project directory.
I deleted all the class files and recompiled them using ant command.
In my case, target name was build-project which compiles all the java files.
So, I did ant build-project
Note - This was done as Eclipse was using different JDK version.
Now, I called my publish class to publish my webservice with
ant publish
This was half done as this was running in interactive mode.
Then I created a bat file with following command -
"path_for_ant_bin_directory\ant" -buildfile "path_to_build_file\build.xml" publish
This was opening up the command box. So, I created a vb script to run the bat file in background
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c path_to_bat_file\my_bat.bat"
oShell.Run strArgs, 0, false
And, now it nicely runs in background and I can access my webservice.
Hope it helps someone with similar requirement.

Using own Java software´s custom update implementation

I have a server, and Client that are working fine, they transfer file to each other and handle commands with success. The thing is that once connected to the server, the server can ask the Client to update itself.
Since I did everything using sockets with a TCP connection, and I am NOT able to use java web start, I am looking for a way I can update the software.
One thing I thought was:
Making the java call another java software and close itself. Then the other java software, would connect to the server again and waits for the update request, so it could replace all files from the current version (lib directory and the jar main file - Im using Netbeans).
Maybe I could just send the connection Object to the Software that would update, but the main only accpets String.
So I ask two questions here:
Is this a good solution? Or is there a better one?
If I do that, how can I send the Client Object of my proto from one application to another?
I would suggest keep a property file on server having latest version of app.
Each time you start the app compare version if its updatable then download all new updates in a temp dir
After SUCCESSFUL download invoke another small application to copy those files to your lib file in order to update your app actually
At the end prompt user that app has been updated and launch the newly updated app. i would say.

Categories