求救!!!Eclipse打包jar后运行报错!!!

xuranyao0416 2010-06-24 11:09:54
用Eclipse里的SWT插件做了一个导入EXCEL数据到数据库中的程序,打包成jar后,无法运行提示
Could not find the main clss:com.jxtele.xcgs.CardMain. Program will exit.
目前我有疑问:我的项目中用到了oracle的ojdbc14.jar,jxl.jar,swt.jar。是不是在打成jar包里要包含这三个jar包?目前的jar包里没有这上包,如果需要的话该怎么加进去。是否还需要其他的jar包。
...全文
267 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
墨梓霖 2011-04-19
  • 打赏
  • 举报
回复
楼主,我项目在eclipse里面能够运行,但是打成war包后,却报错,为啥?
huntor 2010-06-25
  • 打赏
  • 举报
回复
需要依赖的JAR,导出为可执行JAR时,有选择是否一起打包。

也可以选择 Fatjar 或者Onejar插件
Apeipo 2010-06-25
  • 打赏
  • 举报
回复
找不到main?,检查一下你的jar包里的主类的位置与包名一致 - -

如果要要在其他电脑上执行的话肯定得要那些jar吧
工程上右键-》export ->runnable jar file ->弹出的对话框下面的3个选项你看着选
- -这样就能把需要的jar导进去了。
xuranyao0416 2010-06-25
  • 打赏
  • 举报
回复
我已经用fat jar 打包成功,并能运行了。谢谢各位!结贴散分
green_land 2010-06-25
  • 打赏
  • 举报
回复
eclipse自带的打包功能不那么好用
LZ可以试试用Eclipse下的Fat-jar插件打包事半功倍啊
具体参考下http://www.360doc.com/content/09/0618/09/61497_3939628.shtml
thegodofwar 2010-06-25
  • 打赏
  • 举报
回复
估计是打包时出现一些细节问题,再多试试
xd_tracy 2010-06-24
  • 打赏
  • 举报
回复
用Fat打包试试
xuranyao0416 2010-06-24
  • 打赏
  • 举报
回复

prep.setInt(1, Integer.parseInt(strLantId));
prep.setInt(2, Integer.parseInt(strAreaId));
prep.setInt(3, Integer.parseInt(strInputNo));
prep.setInt(4, Integer.parseInt(strSerialNum));
prep.setInt(5, Integer.parseInt(strOutPutNo));
prep.setString(6, strClassId);
prep.setInt(7, Integer.parseInt(strCardNum));
prep.setDouble(8, Double.parseDouble(strMinDiscount));
prep.setDouble(9, Double.parseDouble(strMaxDiscount));
prep.setString(10, strState);
prep.setString(11, strCard_id);
prep.setString(12, strCardMark);
prep.setString(13, strName);
prep.setString(14,strCardNo );
prep.setDouble(15, Double.parseDouble(strParValue));
prep.setDouble(16, Double.parseDouble(strAddValue));
prep.setDate(17, strEffDate);
prep.setString(18, strFrontNo);
prep.setString(19,strStartNo );
prep.setString(20, strEndNo);
prep.setDouble(21,Double.parseDouble(strTotalParValue));
prep.setDouble(22,Double.parseDouble(strTotalAddValue));
prep.setString(23, strInptStaffId);
prep.setTimestamp(24, strInputDate);
prep.setString(25, strInputNote);
prep.setString(26, strAuditStaffId);
prep.setTimestamp(27, strAudditDate);
prep.setString(28, strAuditCause);
prep.setDouble(29, Double.parseDouble(strYsDis));
prep.setDouble(30, Double.parseDouble(strYsFee));
prep.setString(31, strCardType);
prep.setInt(32, Integer.parseInt(strMakeCycleId));
prep.executeUpdate();
}
}
}
book.close();
prep.close();
conn.close();
MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION |SWT.OK);
messageBox.setMessage("导入成功!");
messageBox.setText("提示");
messageBox.open();
}catch(Exception e1)
{
System.out.println(e1);
MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION |SWT.OK);
messageBox.setMessage("报错信息:"+e1+" "+" 导入失败请和系统管理员联系!");
messageBox.setText("提示");
messageBox.open();
}
}
});
button1.setBounds(232, 61, 85, 22);
button1.setText("开始导入");
return container;
}

private void createActions()
{
// Create the actions
}

protected StatusLineManager createStatusLineManager()
{
StatusLineManager statusLineManager = new StatusLineManager();
return statusLineManager;
}

public static void main(String args[])
{
try
{
CardMain window = new CardMain();
window.setBlockOnOpen(true);
window.open();
Display.getCurrent().dispose();
} catch (Exception e)
{
e.printStackTrace();
}
}

protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText("导入程序");
}

protected Point getInitialSize()
{
return new Point(623, 428);
}
}



以上是代码,由于超过输入字符数,没办法只好分两部分。等待高手来解决
xuranyao0416 2010-06-24
  • 打赏
  • 举报
回复

package com.jxtele.xcgs;
import jxl.*;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;

public class CardMain extends ApplicationWindow
{
private Text text;
private String ExcelFilePath;
public CardMain()
{
super(null);
setShellStyle(SWT.CLOSE | SWT.MIN |SWT.TITLE);
createActions();
}
protected Control createContents(Composite parent)
{
Composite container = new Composite(parent, SWT.NONE);
container.setFont(SWTResourceManager.getFont("宋体", 11, SWT.NORMAL));
Button button = new Button(container, SWT.NONE);
FormData data = new FormData();
data.left = new FormAttachment(40);
button.setLayoutData(data);
button.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
dialog.setFilterPath(System.getProperty("C:/Documents and Settings/Administrator/桌面/"));
dialog.setFilterExtensions(new String[] {"*.xls"});
dialog.setFilterNames(new String[] {"Excel Files(*.xls)"});
dialog.open();
ExcelFilePath=dialog.getFilterPath()+"\\"+dialog.getFileName();
text.setText(ExcelFilePath);
}
});
button.setBounds(65, 61, 148, 22);
button.setText("请选择导入的EXCEL文件");
text = new Text(container, SWT.BORDER);
text.setBounds(65, 33, 542, 22);
Button button1 = new Button(container, SWT.NONE);
FormData data1 = new FormData();
data1.left = new FormAttachment(40);
button1.setLayoutData(data1);
button1.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn= DriverManager.getConnection(
"jdbc:oracle:thin:@134.225.54.18:1521:ora8","card","admin12");
PreparedStatement prep = conn.prepareStatement("insert into xry_storage(LATN_ID,AREA_ID,INPUT_NO,SERIAL_NUM,output_no,CLASS_ID,CARD_NUM,MIN_DISCOUNT,MAX_DISCOUNT,STATE,CARD_ID,CARD_MARK,NAME,CARD_NO,PAR_VALUE,add_value,EFF_DATE,FRONT_NO,START_NO,END_NO,TOTAL_PAR_VALUE,total_add_value,INPUT_STAFF_ID,INPUT_DATE,INPUT_NOTE,AUDIT_STAFF_ID,AUDIT_DATE,AUDIT_CAUSE,ys_dis,ys_fee,CARD_TYPE,make_cycle_id)" +
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
Workbook book = Workbook.getWorkbook(new File(ExcelFilePath));
Sheet[] sheet = book.getSheets();
int sheetRowNum = 0;
String tempAudditDate="";
String tempEffDate="";
String tempInputDate="";
String strLantId="",strAreaId="",strInputNo="",strSerialNum="",strClassId="",strCardNum="";
String strMinDiscount="",strMaxDiscount="",strState="",strCard_id="",strCardMark="";
String strName="",strCardNo="",strParValue="";
String strFrontNo="",strStartNo="",strEndNo="",strTotalParValue="";
String strInptStaffId="";
String strInputNote="",strAuditStaffId="",strAuditCause="";
String strCardType="";
String strOutPutNo="0";
String strAddValue="0.00",strTotalAddValue="0.00",strYsDis="0.00",strYsFee="0.00";
String strMakeCycleId="-1";

Calendar newTime = Calendar.getInstance();
SimpleDateFormat formatTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateTemp= formatTime.format(newTime.getTime());
System.out.println("系统当前时间:"+dateTemp);
System.out.println("");

if(sheet!=null&&sheet.length>0)
{
for(int sheetNum=0;sheetNum < sheet.length; sheetNum++)
{
sheetRowNum = sheet[sheetNum].getRows();

for(int rowNum = 1; rowNum < sheetRowNum ; rowNum++)
{
Cell[] cells = sheet[sheetNum].getRow(rowNum);
strLantId=cells[0].getContents();
strAreaId=cells[1].getContents();
strInputNo=cells[2].getContents();
strSerialNum=cells[3].getContents();
strClassId=cells[4].getContents();
strCardNum=cells[5].getContents();
strMinDiscount=cells[6].getContents();
strMaxDiscount=cells[7].getContents();
strState=cells[8].getContents();
strCard_id=cells[9].getContents();
strCardMark=cells[10].getContents();
strName=cells[11].getContents();
strCardNo=cells[12].getContents();
strParValue=cells[13].getContents();
if(cells[14].getType()==CellType.DATE)
{
DateCell dateCell=(DateCell)cells[14];
Date date=dateCell.getDate();
tempEffDate=new SimpleDateFormat("yyyy-MM-dd").format(date);
}
java.sql.Date strEffDate=java.sql.Date.valueOf(tempEffDate);
strFrontNo=cells[15].getContents();
strStartNo=cells[16].getContents();
strEndNo=cells[17].getContents();
strTotalParValue=cells[18].getContents();
strInptStaffId=cells[19].getContents();
if(cells[20].getType()==CellType.DATE)
{
DateCell dateCell=(DateCell)cells[20];
Date date=dateCell.getDate();
tempInputDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
}
java.sql.Timestamp strInputDate=java.sql.Timestamp.valueOf(tempInputDate);

strInputNote=cells[21].getContents();
strAuditStaffId=cells[22].getContents();
if(cells[23].getType()==CellType.DATE)
{
DateCell dateCell=(DateCell)cells[23];
Date dateTime=dateCell.getDate();
tempAudditDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateTime);
}
java.sql.Timestamp strAudditDate=java.sql.Timestamp.valueOf(tempAudditDate);

strAuditCause=cells[24].getContents();
strCardType=cells[25].getContents();


62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧