Running a Java program automatically at a specified time
How to run a Java appln automatically at a specified time?
Java Application, or method within a running Java application?
To run Java you would have to use the OS native tools.
Windows Scheduled Tasks
Newbie: Intro to cron.
To execute a block of code within a running Java VM, you want to look at Timer.
Similar Messages
-
Running a java program a set number of times
This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
Hope this helps -
Running a java program in a directory other than the current directory
How do I run a java program that's located in a directory other than the current directory?
There is a file Test.java in /dir1/subdir1. If my current directory is anywhere other than that directory, say /dir2/subdir2, I can compile Test.java by using:
javac -classpath /dir1/subdir1 /dir1/subdir1/Test.java
But when I try to run it with:
java -classpath /dir1/subdir1 /dir1/subdir1/Test
I get a java.lang.NoClassDefFoundError: \dir1\subdir1\Test
Any thoughts?You need to specify just the name of the class you want to run. So java -classpath /dir1/subdir1 Test
-
URGENT: How to run a Java program from a different directory?
Hi.
How do I run a Java program from a directory that the file is not located in? So lets say im in c:\Java. But the file is in c:\Java\abc\efg\.
What would be the command to run the Java file from c:\Java.
I can't remember it and I need it asap.
Cheers.If the class you are trying to run is MyApp.class, try
c:\Java\>java -cp abc\efg MyAppThe actual classpath you specify will depend on whether or not MyApp.class is in a package (I've assumed it isn't) and whether or not any 3rd party jars are involbed (I've assumed not).
Edited by: pbrockway2 on Apr 1, 2008 6:42 PM
The command arguments read as "Run the MyApp class using as a classpath abc\efg relative to here (c:\Java)". -
How to run a java program in command prompt
hi i want to run a java program from in command prompt from another directory
i want to run a file named First in C:\Program Files\Java\jdk1.6.0_07\bin
so when i give the command
java "C:\Program Files\Java\jdk1.6.0_07\bin\First"
it doesnt works it shows
C:\>java "C:\Program Files\Java\jdk1.6.0_07\bin\First"
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Program Files\Java
\jdk1/6/0_07\bin\First
Caused by: java.lang.ClassNotFoundException: C:\Program Files\Java\jdk1.6.0_07\b
in\First
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: C:\Program Files\Java\jdk1.6.0_07\bin\First. Pro
gram will exit.but it prints
C:\>java -cp "C:\Program Files\Java\jdk1.6.0_07\bin\" First
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
C:\> -
Help needed in running a java program
hi
how to run a java program using another java program.
i have tried a litte to run the notepad,mspaint applications sucessfully using the Runtime class,but how to specify a java program init . the program is given below
public class cls
public static void main(String args[])
Runtime r=Runtime.getRuntime();
Process p=null;
try{
p=r.exec("notepad" );}
catch(Exception e) {
System.out.println("error on execution");
}to run another java program how to modify the exec() or any other way to do this.thank u
its working without any error but it doesn't print any thing on the screen.
the program is
this program to be run by cls.java
// hello.java
import java.io.*;
public class hello
public static void main(String[] args)
System.out.println("hello world");
}cls.java is given below
//cls.java
public class cls
public static void main(String args[])
Runtime r=Runtime.getRuntime();
Process p=null;
try{
p=r.exec("java hello" );}
catch(Exception e) {
System.out.println("error on execution");
} -
How to run a java program in another folder
Hello!
I want to run for example the java class file in the path ./sourcecode/javafile.class. It works fine if I do the following:
cd sourcecode
java javafile
but it cannot work if I do:
java sourcecode/java
The error it outputs is NoClassDefFoundError.
Can someone tell me how to run a java program in another folder
thanks a lot.You need to specify the classpath using the -cp flag when running. so instead of
"java sourcecode/javafile"
Try
"java -cp sourcecode javafile" -
Error while running a Java Program
Can anyone help me,
I am getting the following error while running a Java program, Below is the exception thrown, please help.
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:425)
at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
at org.jetel.graph.Edge.writeRecord(Edge.java:288)
at com.tcs.re.component.RESummer1.run(RESummer1.java:505)
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:425)
at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
at org.jetel.graph.Edge.writeRecord(Edge.java:288)
at com.tcs.re.component.RECollectCont.run(RECollectCont.java:304)Ok, let's see. Write the following class:
public class Grunt {
public static void main(String[] args) {
System.out.println("Hello Mars");
}Save it as "C:\Grunt.java", compile by typing:
javac c:\Grunt.javaRun by typing:
java -classpath "C:\" GruntDoes it say "Hello Mars"? If yes, go back to your program and compare for differences (maybe you used the "package" statement?).
Regards -
Running a java program from an icon
I want to run my program from an icon on my desktop. I have a .bat file that I've built a shortcut to and it works.MY GUI program does display and run when I click on the icon. The problem is that the DOS window also shows up behind my GUI.
Is there anyway to prevent the DOS window from showing? Or is there another way to run a Java program without resorting to a DOS command line or running it through FORTE or another IDD?Chris's solution worked well, with one small problem. Once my GUI starts, it takes up the whole screen. Normally when I run it, it appears as a small window.
not a big problem, I can reduce it easily after it starts. But does anyone know a way to make it come up in the reduced size it norally comes up in when I run it from my IDE? -
Running a java program via a batch file
I am unable to run a java program from a batch file that I created.
spiderpackage.EntryPoint is a class file which I am trying to run with a -v option to output something.What should I do to get the output?
echo ^<html^>^<body^>
echo hello^<br^>
call java spiderpackage.EntryPoint -v
echo ^</body^>^</html^>This has nothing to do with java programming. Have a look at the windows help for the call command.
The echo <html> stuff doesn't make sense. What's it for?
The command in you batch file should be:
java -cp . spiderpackage.EntryPoint -v
assuming that java is in the system path, and the EntryPoint.class is in a directory called spiderpackage which is a subdirectory of your current working directory -
Running a Java program at startup in Linux
Hello
How do I run a Java program at startup in Linux? I know in Windows I can put a .bat file in C:\Windows\Start Menu\Programs\StartUp\ directory, but in Linux I have no idea how it is done.
Thank you,
MihaiThis is really a Linux question, not Java.
And then it depends on the version of Linux you are using.
Maybe this will help, otherwise you should try on a forum for your version of Linux. -
Exception while Running a Java Program for UME.
Hi Experts,
I am trying to run a java program to acess UME. Its a sample to create user but all of my samples are throwing this exception in NWDS (Console).Can anyone tell me why is it throwing this exception .
com.sap.security.api.UMRuntimeException: UME factory 'com.sap.security.api.IUserFactory' cannot be accessed because UME initialization has not started yet.
Please check
UMFactory.isInitialized() before using UME functionality.
at com.sap.security.api.UMFactory.checkInitialized(UMFactory.java:1019)
at com.sap.security.api.UMFactory.getUserFactory(UMFactory.java:801)
at Search.main(Search.java:25)
Exception in thread "main"
Thanks in advance
SomilHi,
Earlier i faced the same exception when i tried to call the UME form Standalone java application,To resolve this i used stateless session bean approach. i follow the Below Mentioned Steps,
1:-- create an J2EE -- EJB module project.
2:-- Create stateless session bean and define the require methods ,implement Local and remote interface methods in your bean class.
3:-- refer the UME apis in EJB Projects build path.
4:-- Call UME in Bean class methods.Build the EJB project and Archive.
5:--Now create an Enterprise application Project ,Include the EJB module project to your EA Project by right clicking on EA project.Build EA project and EAR file
6:--Deploy the EAR file on your server.
7:--Now from your standalone java application include these two projects in Project tab of your Application.
8:--Lookup the stateless session bean in your java class by its default JNDI name ,Obtain remote or local Home interface,And execute the BEAN Method which deals with UME.
You can also refer this tutorial in some parts of it UME apis(like IUser,UMFactory) are used in Servelets and EJB ,You can download this tutorial source from SDN for your reference.
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/297f35cf-0201-0010-00b2-fe2f3e23d360
Siddharth -
Not able to run a java program on Sun Solaris
Hi All,
I am getting following error while running a java program. Can you help.
Thanks,
--Srini
Error:
Exception in thread "main" java.lang.NoClassDefFoundHi Sergi,
Thanks for the info. I couldn't able to login because of my internet connection.
Thanks,
--Srini -
How to set path to run a Java program?
my pc os is win2000 service pack 3.
cpu is celoron 667mhz
256 pc133 sdram
i have done the setting b4 run a java program but no any effect.
setting as below:
set path=c:\j2sdk1.4.1_01\bin
set classpath=c:\j2sdk1.4.1_01\lib
my java file is store in C:\Java, file name is HelloWorld.java, so when i type:
C:\>
C:\>Java\javac HelloWorld.java
(the screen show me : java\javac not internal or external........")
and i try again as follow:
C:>
C:>\Java>javac HelloWorld.java
(the screen show : Exception in thread "main" java.lang.NoClassDefFoundError:HelloWorld/java)
i cant do anymore, who can help me?you need to put the CLASSPATH to dir: c:\j2sdk1.4.1_01
and also to the directory you are working
For example, you are working in "C:\Myclasses". You need to put:
set CLASSPATH = C:\j2sk1.4.1_01;C:\Myclasses;
if you don't put your working directory, java doesn't find your classes
Try it and luck! -
Is it possible to run a java program without using the command prompt?
Hi,
I was wondering whether it is possible to run a Java program (not an applet) without using a command line in the command prompt?
Basically I want to run a program that will be continually running in the background and hence I don't want to have a command prompt screen loaded up as well - I just want the program to be running in the task bar.
I know how to run the program in the task bar - but I still need to launch the program from the command prompt - is there anyway I can get a program running without having to start it from the command prompt?
CheersOr create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).
Maybe you are looking for
-
How to create a Job portal in dreamweaver
I want to create a job and recruitment website using mysql database Please how do i do that. thanks
-
How to add a column in existing DTW template
Dear Expert, I want to add a column which is in table structure of JDT1 but in DTW template that column is not there... In my JDT1 table that column has some value and i want that value to be enter thru DTW .. Give me step because at some stage i m m
-
Contacts modified on iPhone - changes disappear
I have had the opportunity to make changes to a contact record on the iPhone but when I return to my desk and plug the phone the changes are gone! Thank God I've been able to remember what updates I made, otherwise it's a royal pain in the rear and t
-
Does Tomahawk FileUpload work Fine with the latest Apache/Java EE tecnology
Hi all, I am beginning to think that Tomahawk FileUpload (tomahawk-1.1.3.jar) cannot work fine with EJB3.0? Has anyone tried this combination yet? I was trying the steps given using the following link:http://wiki.apache.org/myfaces/Setup_For_File_Upl
-
How do I stop "Camera Window" from launching every time I plug in my iPhone
When ever I plug my iPhone into my computer to sync the application "camera window" pops up telling me there is no camera connected, then I have to click ok for the box to go away. Is there any way I can get it to stop doing this?