我Eclipse写了个小程序,如何编译为一个独立的程序呢?
import java.io.*;
public class Delete { /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
if (args.length != 1)
{
System.err.println("参数错误");
System.exit(0);
}
try
{
MyDel(args[0]);
}
catch(IllegalArgumentException e)
{
System.err.println(e.getMessage());
}
}
public static void MyDel(String FileName)
{
File f = new file(FileName);
if (!f.exists()) fail("不存在文件或目录:"+FileName);
if (!f.canWrite()) fail("写保护,不能删除:"+FileName);
if (f.isDirectory())
{
String files = f.list();
if (files.length()>0)
fail("不能删除非空文件夹");
}
boolean b = f.delete();
if (!b) fail("删除出错!");
}
protected static void fail(String msg) throws IllegalArgumentException
{
throw new IllegalArgumentException(msg);
}
import java.io.*;
public class Delete { /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
if (args.length != 1)
{
System.err.println("参数错误");
System.exit(0);
}
try
{
MyDel(args[0]);
}
catch(IllegalArgumentException e)
{
System.err.println(e.getMessage());
}
}
public static void MyDel(String FileName)
{
File f = new file(FileName);
if (!f.exists()) fail("不存在文件或目录:"+FileName);
if (!f.canWrite()) fail("写保护,不能删除:"+FileName);
if (f.isDirectory())
{
String files = f.list();
if (files.length()>0)
fail("不能删除非空文件夹");
}
boolean b = f.delete();
if (!b) fail("删除出错!");
}
protected static void fail(String msg) throws IllegalArgumentException
{
throw new IllegalArgumentException(msg);
}
那么需要把jre 一起打包进去