windows任务计划程序不能正常执行jar解决思路

   阅读
windows任务计划程序不能正常执行jar
Java code

package com.file.Test;

import java.io.File;

public class Test {

    public static void main(String[] args) {
        System.out.println("run Test");
        Test t = new Test();
    }
    
    public Test(){
        System.out.println("run...");
        try{
            File myFilePath = new File("E:\\test");
            if(!myFilePath.exists())
            {
                myFilePath.mkdir();
            }
            
        }catch (Exception e) {
          System.out.println("新建目录操作出错");
          e.printStackTrace();
        }
        
    }
}


MANIFEST.MF
-------------------------------
Manifest-Version: 1.0
Class-Path: .
Main-Class: com.file.Test
-------------------------------

生成jar后双击是可以正常运动并生成文件夹.另外将jar放到windows下的自动启动程序文件夹(C:\Users\XXX\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)也都可以正常运行.但将其添加到windows任务计划程序就会报错[b][/b]: Could not find the main class:E:\Ntest.jar. Program will exit.

如下是windows任务计划程序截图


------解决方案--------------------
考虑下你的jar包在计划任务启动时采用bat去启动。因为计划任务可能找不到你环境变量中的jdk,你在bat中可以设置好你的JAVA_HOME等参数,应该是没问题。
阅读