批处理调用java文件,bat中怎么引入jar包。
java文件:
---------
package com.soft.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Jdbc12 {
public static void main(String args[]){
System.out.println( "Copyright 2004, R.G.Baldwin");
try {
Statement stmt;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url, "root", "root");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
stmt = con.createStatement();
for(int i=200 ;i<300;i++){
stmt.executeUpdate("insert into log values("+i+","+i+")");
System.out.println(i);
}
con.close();
}catch( Exception e ) {
e.printStackTrace();
}
}
}
==============================================
jar文件:
--------
mysql-connector-java-5.1bin.jar
==============================================
bat文件:
---------
D:
cd javatest\Test\src\com\ztesoft\test
javac *.java
java Jdbc12
------解决方案--------------------
java -Xmx512M -cp .;lib/ECLA.jar;lib/DTNConsoleConnection.jar core.DTNSim %*
给个例子给你,这个是bat文件的内容,可加多个参数
其中core.DTNSim是main函数所在类,.后面那两个是导入到jar包
还有一种方法更简单一点,你打成的jar包里面有个META-INF,里面还有个MANIFEST.MF,把里面内容修改一下
Manifest-Version: 1.0
Sealed: true
Main-Class: core.DTNSim
Class-Path: junit.jar ECLA.jar DTNConsoleConnection.jar
记得两个包中间用空格,怎么写自己应该能看清楚吧