简体   繁体   中英

Task Scheduler Does Not Start Bat File

My bat file is:

 @echo off 
 java -cp * MyTimerTasker

I try to run main function in MyTimerTaskerClass. All jars and bat file are in same folder. When I try to run bat file with double click, it runs. When I try to run with right click and run as administrator, command window shows and disappears but my main function does not start. When I try to run with task scheduler, it never starts.

Edit: My main class.

 public class MyTimerTasker {
 public static void main(String[] args) throws IOException {
    FTPDownloadFiles ftpDownloadFiles = new FTPDownloadFiles();
    System.out.println("Running ...");
    DatabaseTask databaseTask = new DatabaseTask();
    databaseTask.connectToDatabase();
    ftpDownloadFiles.downloadFiles();

    try {
        databaseTask.parseFiles(JdbcConnection.filesPath);
    } catch (SQLException e) {
        e.printStackTrace();  
    } catch (Exception e) {
        e.printStackTrace();  
    }
    finally {
        try {
            databaseTask.closeConnection();
        } catch (SQLException e) {
            e.printStackTrace();  
        }

    }

}
}

You are adding the classpath of all the files in the working directory. You should add the name of the jar to the classpath.

If you start as administrator, it starts in another directory (same if you start as a scheduled task). You will have to set your working directory in the batchfile:

cd /d "%~dp0"

This will change the working directory to the folder, where your batchfile resides.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM