首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

将java程序打包之后,双击生成的jar文件,老是出现异常提示,用eclipse打包的

2011-12-13 
将java程序打包之后,双击生成的jar文件,老是出现错误提示,用eclipse打包的双击之后老是出现:couldnotfindt

将java程序打包之后,双击生成的jar文件,老是出现错误提示,用eclipse打包的
双击之后老是出现:could   not   find   the   main   class.         Program   will   exit.

其它程序打包都没有问题,就单单这一个出现问题,我不知道是为什么,麻烦各位高手指点,我也手工打包过,还是不行,程序如下:

package   yuebao;

import   java.io.*;
import   java.text.*;

import   org.apache.poi.hssf.usermodel.*;
import   org.apache.poi.poifs.filesystem.POIFSFileSystem;

public   class   CallRecord
{
public   static   void   main(String[]   args)
{
int   b=0;
POIFSFileSystem   pfs=null;
HSSFWorkbook   hwb=null;
try
{
pfs=new   POIFSFileSystem(new   FileInputStream( "CallRecord(Running).xls "));
hwb=new   HSSFWorkbook(pfs);
HSSFSheet   sheet=hwb.getSheetAt(0);
int   rowNum;
int   i;
    String[]   date=new   String[3100];
    double[]   record=new   double[3100];
    double[]   percent=new   double[3100];
    rowNum   =   sheet.getLastRowNum();
    //System.out.println(rowNum);
    for   (i   =   4;   i   <=   rowNum;   i++)   {
    //System.out.println(sheet.getRow(i).getCell((short)0).getDateCellValue().toLocaleString());
      date[i]=sheet.getRow(i).getCell((short)0).getDateCellValue().toLocaleString();
      HSSFCell   cl=sheet.getRow(i).getCell((short)1);
      record[i]=Double.parseDouble(cl.toString().trim());
      HSSFCell   c2=sheet.getRow(i).getCell((short)2);
      percent[i]=Double.parseDouble(c2.toString().trim());
      //System.out.println(i+ "--- "+date[i]+ "--- "+record[i]+ "--- "+percent[i]);
      }
   
    HSSFWorkbook   wb=new   HSSFWorkbook();
FileOutputStream   fo=new   FileOutputStream( "callRecord.xls ");
HSSFSheet   ht=wb.createSheet( "彩铃月报 ");
HSSFRow   r1   =   ht.createRow((short)0);
                HSSFCell   c1   =   r1.createCell((short)0);
                c1=r1.getCell((short)0);
                c1.setCellValue( "日期1 ");
                HSSFCell   c2   =   r1.createCell((short)1);
                c2=r1.getCell((short)1);
                c2.setCellValue( "日期2 ");
                HSSFCell   c3   =   r1.createCell((short)2);
                c3=r1.getCell((short)2);
                c3.setCellValue( "忙时试呼次数 ");
                HSSFCell   c4   =   r1.createCell((short)3);
c4=r1.getCell((short)3);
c4.setCellValue( "忙时应答率 ");
    double[]   result1=new   double[93];
    int   start=4;
    int   end=96;
    int   n=0;
    for(int   j=start;j <=end;j++)
    {


    int   m=n++;
    result1[m]=0;
    //System.out.println(m);
    for(int   k=0;k <4;k++)
    {
    result1[m]=result1[m]+record[j+k];
   
    }
    //System.out.println( "result1[ "+m+ "]: "+result1[m]);
    //System.out.println( "j: "+j);
    if((end-j)==0)
    {
    b++;
    float   max=(float)result1[0];
    float   per=(float)0;
    int   l1=0;
    for(int   l=1;l <result1.length;l++)
    {
    if(max <result1[l])
    {
    max=(float)result1[l];
    l1=l;
    }
    }
    for(int   t=0;t <4;t++)
    {
    per=(float)(per+percent[96*((j/96)-1)+4+l1+t]);
    //System.out.println(date[96*((j/96)-1)+4+l1+t]+ "--- "+record[96*((j/96)-1)+4+l1+t]+ "--- "+percent[96*((j/96)-1)+4+l1+t]);
    }
    DecimalFormat   df=new   DecimalFormat( "##.00 ");
    //System.out.println( "max----- "+max+ "per: "+df.format(per*100/4));
   
    if(end+3 <=rowNum){
    HSSFRow   r2   =   ht.createRow((short)b);
                HSSFCell   hc1   =   r2.createCell((short)0);
                hc1=r2.getCell((short)0);
                hc1.setCellValue(date[96*((j/96)-1)+4+l1]);
                HSSFCell   hc2   =   r2.createCell((short)1);
                hc2=r2.getCell((short)1);
                String[]   s=date[96*((j/96)-1)+4+l1].split( "   ");
                hc2.setCellValue(s[0]);
                HSSFCell   hc3   =   r2.createCell((short)2);
                hc3=r2.getCell((short)2);
                hc3.setCellValue(max);
                HSSFCell   hc4   =   r2.createCell((short)3);
hc4=r2.getCell((short)3);
hc4.setCellValue(df.format(per*100/4)+ "% ");
    end=j+96;
    }
    else
    {
    break;
    }
    j=j+3;
    //System.out.println( "come   in ");
    n=0;
    }
    }
   

wb.write(fo);
fo.close();
}
catch   (FileNotFoundException   e)
{
e.printStackTrace();
}
catch(IOException   e)
{
e.printStackTrace();
}
}
}


[解决办法]
你采用了 Apache POI 的外置包,需要自己创建 MANIFEST.MF 文件,在里面写上



Manifest-Version: 1.0
Created-By: 1.5.0_01 (Sun Microsystems Inc.)
Main-Class: yuebao.CallRecord
Class-Path: lib/poi-3.0-rc4-20070503.jar(写上POI jar的文件名,我这里仅作示例,若还有其他的使用空格分开)

建好后,在这个文件下敲几个回车。

使用 Eclipse 的 Export 功能,在你按了三次“Next”(JAR Manifest Specification)后,选择 Use existing manifest from workspace,Browse 找到刚才新建的那个文件。按 Finish 结束。

找到生成的 jar 文件,与该文件平级建一个 lib(名字与 Class-Path 中的一致)目录,将外置的 jar 包拷进去,再退回上一层,这个 jar 文件就可以运行了。

不知道我啰嗦了那么多,明白了吗?
[解决办法]
http://www.jopener.cn/category/installers-generators/
[解决办法]
pfs=new POIFSFileSystem(new FileInputStream( "CallRecord(Running).xls "));

---------------------------------------

你都打成jar包了~这个文件还怎么生成~
你最好改用绝对路径~

[解决办法]
to: daniel_kaka

相对路径文件可以生成的,我试过,生成的位置与 jar 同级。

热点排行
Bad Request.