Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I did a reminder application in java.I want to run that application only at 12 P.M So that it then generates a mail to client .The thing to generate mail is done,but the main issue now is how to make application run exactly at 12 P.M daily...
Use cron (Unix only)
Add this to your cron tab
0 0 * * * /path/to/your/file.sh >/dev/null 2>&1
file.sh
#!/bin/sh
java com.package.YourMainClass
edit
On Windows 8, take a look here : Using Task Scheduler in Windows 8
You can keep the application running and do the scheduling yourself. For example, using Quartz
If you're on UNIX, you can use cron.
It can be solved in two ways. 1. Have the OS run it once a day using cron or other scheduler.
The other is to install your program as serice using http://sourceforge.net/projects/yajsw/ or other service wrapper helper.
Then have your program run in the back ground, with a timer every minute. When its time, do the tasks. This is great as your program can easily accept config for other triggers as well. Advantage of installing it as a service is that it will run automatically on system start and keep running in the back ground. Make sure you catch exceptions, log them but try to keep running so the program does not exit on recoverable and transient errors.
In both cases you will make a non UI program with an optional UI program that writes to java preferences API to tell the daemon any user specific preferences.
The service app can be run from command line as well if you dont want to install a few users do not want to install it as a service.
For timer can see How to set a timer in java
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I tried running StartSonar.bat file, but it would stop or close abruptly.
Below is the snapshot of sonarqube server error:
We need to have the java 11 version installed for static tool analysis on sonarqube. For download and set up follow this link:
https://java.tutorials24x7.com/blog/how-to-install-java-11-on-windows
Even after this if you face an issue opening the StartSonar.bat file then, check task manager and kill all process/tasks related to java jdk. Because If you had already started Sonar and killed the process on command prompt, your JVM would still be running in the background.
If the issue is not solved then go to conf folder in sonarqube and open sonar properties file and search for the 9000 port number and change sonar.web.port value to some other port number Eg.9050 and uncomment it.
Similarly, search for port number 9001 and follow the same process.
The error suggest that you port 9001 is already use. Probable reasons:
Another program using it. Check Task Manager -> Performance -> Open Resource Monitor ->Network ->Listening Ports
Another instance of SonarCube is running and using it.
Previous instance of SomarCube was not ended properly.
Solutions:
If 1, then change the port of SonarCube server to something else. Read this.
If 2, then you can wait till it ends.
If 3, restart your system.
Sonar is trying to connect on port 9001 which is already in use. Take a look at what's running on port 9001 by navigating to Resource Monitor -->Network -->Listening Ports
In sonar.properties file, Change sonar port 9001 to any other available port. For example- 9003. Save the file and run the script StartSonar.bat to start sonar
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
In my Spring-boot application, I am trying to trigger a shell script which in turns internally executes several other shell scripts.I am able to trigger my main script (say master.sh) using ProcessBuilder, but thereon any scripts being called within master.sh do not run. In fact, nothing happens.
At a high-level, I am trying to do the following in my master.sh -
Check for some condition
Execute another shell script This never executes hence no further statements execute.
make curl call back to my spring-boot app
.....
Any help please...
Quick recap of the use case I was struggling with - In my spring-boot app, user has an option to trigger a main script (say master.sh) - this main script internally does the below -
(a). Executes another script present at some other location on the system :: this script could take anywhere between 30 mins - 3+ hours to execute.
(b). Once step (a) completes, master.sh (main script) runs curl commands to make a callback to my Spring boot application in order to perform updates to the DB.
Above steps a & b are executed multiple times inside the master.sh
Solution : As for triggering any command from Java code, i used ProcessBuilder to achieve the same. But I had to add below additional statements before issuing processBuilder.start() call in order to make it work -
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
Above statements redirect the script output to the parent process's (in this case Java) error and output streams.
At the moment it has worked for me. In case the behavior changes (which I don't anticipate) then I will update this thread accordingly.
Lastly, I would request others to share their understanding on why without the above two statements my internal scripts did not run. I do understand the "why" but not finding a clear wording to explain. Thanks All.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I would like to create a simple HTTP server in Android for serving some content to a client.
Any advice on how to build the server or use any existing library?
Consider this one:
https://github.com/NanoHttpd/nanohttpd.
Very small, written in Java. I used it without any problem.
NanoHttpd works like a charm on Android -- we have code in production, in users hands, that's built on it.
The license absolutely allows commercial use of NanoHttpd, without any "viral" implications.
This can be done using ServerSocket, same as on JavaSE. This class is available on Android. android.permission.INTERNET is required.
The only more tricky part, you need a separate thread wait on the ServerSocket, servicing sub-sockets that come from its accept method. You also need to stop and resume this thread as needed. The simplest approach seems to kill the waiting thread by closing the ServerSocket.
If you only need a server while your activity is on the top, starting and stopping ServerSocket thread can be rather elegantly tied to the activity life cycle methods. Also, if the server has multiple users, it may be good to service requests in the forked threads. If there is only one user, this may not be necessary.
If you need to tell the user on which IP is the server listening,use NetworkInterface.getNetworkInterfaces(), this question may tell extra tricks.
Finally, here there is possibly the complete minimal Android server that is very short, simple and may be easier to understand than finished end user applications, recommended in other answers.
Another server you can try http://tjws.sf.net, actually it already provides Android enabled version.
If you are using kotlin,consider these library.
It's build for kotlin language.
AndroidHttpServer is a simple demo using ServerSocket to handle http request
https://github.com/weeChanc/AndroidHttpServer
https://github.com/ktorio/ktor
AndroidHttpServer is very small , but the feature is less as well.
Ktor is a very nice library,and the usage is simple too
You can try Restlet edition for android:
The source can be downloaded from Restlet website:
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have written some Java code to keep getting some value in other website every 10sec.
And I will keep writing the result to append a txt file.
How can I keep running this code.
Should I run it in some cloud server?
If so, how can I do it.
I just know in Eclipse, I click "run application".
How can I run in other ways(Linux, or without Eclipse)?
Here is what you can do, using a loop, shell script and a cron job to achieve what you need:
Make sure your program has the logic something like an infinite loop to run always.
Then write a shell script to invoke your java program with the necessary arguments.
Make sure that the classpath argument points to the jars that you need.
Make sure that the shell script has necessary linux permissions.
Schedule the script to be invoked by setting up a cron job. You can set the cron condition as per your need.
If you used eclipse, then you probably have created a jar file. In that case to run it outside eclipse:
java -jar <path-to-jar-file.jar>
Make sure you are in the correct folder before running above.
Eclipse is an IDE, meaning it allows you to edit and run code. When you click the Play button to run a project in eclipse, for each of your *.java files in the project workspace, another *.class file gets created. This is your code compiled to something the JVM (Java Virtual Machine) understands, and can be translated into machine languange and be ran.
These .class files can be run from the command line as well:
java myProgram.class
(Assuming you have the JRE in your environment variables). This can be done from any jvm on any platform, as long as your code is designed to be cross platform (Not using Windows specific APIs for example).
To stop the app, you can either implement a method that stops it, or kill its process. As for cloud computing, this is too broad a topic to just shoot you an answer here, but yes, you can run your code on a linux machine for example.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm pretty new to some of these concepts so I hope you guys take it easy on me over this.
I want to run a program at start up in Ubuntu which I called Message.java. I did a little research and figured I could move Message.Class (someone told me to compile .java into a class first) into /etc/init.d. Then I used these commands:
sudo mv Message.class /etc/init.d/
sudo chmod +x /etc/init.d/Message.class
sudo update-rc.d Message.class defaults
What I want is for a simple message dialog with "Hello World" to display at startup. So far, nothing happens. Can someone tell me what I'm doing wrong? Do I even have the right idea? (I'm just going off other posts). And if I'm completely wrong can someone point towards a good tutorial? Here's the code just in case:
public class Message {
public static void main(String[] args) {
// TODO Auto-generated method stub
Component frame = null;
//default title and icon
JOptionPane.showMessageDialog(frame,
"Hello World");
}
}
Firstly, init.d is run on system startup. System startup is not when you log into the desktop, but when the operating system has reached a certain point in the boot process. init.d is typically used for running background processes and services.
Also, when you put in init.d has to be executable. A .class file isn't executable. You have to run a .class file by using the java command (eg. java HelloWorld). You would need to make a bash script to start it if you wanted it to run at this point.
(These aren't criticisms, just things to try and understand about how the architecture works. I didn't understand them when I started either.)
However since you want it to run when the user logs in you'll need to use another method. Depending on what flavor of Ubuntu you have you'll need to do something different. If it's the default and a recent version then you'll need to figure out how Unity run things on user login. If it's a Gnome or KDE flavor you'll need to find out those respective desktop environments run things when a user logs in.
I'll assume you have Unity and see if I can find a good simple guide to set a 'program' (again you'll need to make a small file that run your java command) to run on user login.
EDIT:
This guide seems to be rather comprehensive on how to set a program to run on login. You'll want to put the full path to your bash script in the 'command' box.