• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Unable to run a .JAR as a windows Scheduled Task  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've developed an application and made a .JAR file out of it. It seems to work just fine. I doubleclick it, and it starts right up. It even does what it's supposed to do, which I view as an added bonus.

HOWEVER, if I try to run it as a Windows Scheduled Task, it fails spectacularly, this failure is accompanied by the following cold and uncaring dialog box:

Java Virtual Machine Launcher

Could not find the main class. Program will exit.



I was hoping to run the task nightly, as it's a bit time consuming. I've set up the task to run under my user account, with my login password. Though I realize this may be more of a Windows Thing than a Java Thing, I'm at a loss as to why it wouldn't work.

If anyone could point me towards a solution I would be eternally grateful, as will be my children, and my children's children.

Thanks.
 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also,

The manifest file contains the following:



Whis is correct, as far as package and name are concerned. Like I said, it works if I doubleclick it.
 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update,

I've worked around this issue by writing a batch file to run the .JAR, and adding the batch file to Scheduled Tasks. The good news is it works now. The bad news is, I haven't learned why it didn't work in the first place. An unfortunate state of affairs, to be sure.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Adam. Altmann.:
Hello,

I've developed an application and made a .JAR file out of it. It seems to work just fine. I doubleclick it, and it starts right up. It even does what it's supposed to do, which I view as an added bonus.

HOWEVER, if I try to run it as a Windows Scheduled Task, it fails spectacularly, this failure is accompanied by the following cold and uncaring dialog box:



I was hoping to run the task nightly, as it's a bit time consuming. I've set up the task to run under my user account, with my login password. Though I realize this may be more of a Windows Thing than a Java Thing, I'm at a loss as to why it wouldn't work.

If anyone could point me towards a solution I would be eternally grateful, as will be my children, and my children's children.

Thanks.



Wow, your children's children? I doubt I'll live long enough, but I suspect you just entered the jar itself as the command. You should make sure the system has %JAVA_HOME% set and that %JAVA_HOME\bin is in the %PATH% (for all users), and then the command should be:

%JAVA_HOME\bin\java.exe -jar myprogram.jar

and it should run in an appropriate folder.

Mark
 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I can run it from the Command Line. I've got:

C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.5.0_03

C:\>echo %CLASSPATH%
.

C:\>echo %PATH%
C:\Program Files\Java\jdk1.5.0_03\bin;


I think that covers everything. I can run my application from the command line, or by double-clicking on it. If I go to add a Scheduled Task, and browse to the .JAR and add it that way. I get the "Cannot find main class" error dialog. But if I run a batch file including "java -jar Application.jar", it works just fine.

Am I missing something with either JAVA_HOME, PATH, or CLASSPATH?

Thanks for your help.
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, in Scheduled Tasks-> Properties for your task, what is in the "Run:" field?

Mark
 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The path to the .JAR file.

"C:\Documents and Settings\user\Desktop\Application.jar"

or

"C:\Applications\Application.jar"

etc.

It doesn't seem to matter where it is, it won't run if I set the Scheduled Task up like this...though it seems that Windows is trying to run it, since it produces the lovely JVM error.

Though if I set up the batch file as so:



...Scheduled Tasks will run it just fine.
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the "Run:" field, I believe it must have the "java -jar" part just like your batch file. I.e.: your task is set as if you had created the batch file like this:


Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!