java程序打包后JAR后运行特别慢原因

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xyjincan/article/details/86547344

使用eclipse导出 Runable JAR File 单个文件

Export
Runable JAR file

选择启动类:
Launch configuration

选择导出位置及文件名
Export destination:

1、 重新打包,抽取依赖jar包的类,合并打包成一个jar文件

Extract required libraries into generated JAR	
有重打包,注意开源工具协议问题

2、 将原始依赖jar直接打包进jar

Package required libraries into generated JAR
不涉及修改第三方工具库

3、 建一个子文件夹库,放jar包

Copy required libraries into a sub-folder next to the generated JAR
打包后有多个文件

其中使用2方法时,启动jar会造成巨大的磁盘IO,一个一次性批处理程序初次运行时极为缓慢(加载大量库类时)

java version “1.8”
Java™ SE Runtime Environment ()
Java HotSpot™ Server VM (build mixed mode)

(本人程序使用Apache POI 库,输出一个xlsx表格或是docx文档)

大半年才突然发现这个原因,,,

展开阅读全文

关于JBuilder2008,java程序打包后却不能运行

05-29

问题描述:我用的是JBuilder2008(JBuilder2008和eclipse很像的,所以请大家不需要说明其他版本的操作方法),问题就是我的一个工程打包成jar包以后不能运行。请有经验的人帮我分析一下!!!先谢谢大家了!rn下面开始贴图,关于我打包的过程:rn1:下面是我要打包的工程rn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\360安全浏览器截图4689936.jpg][/img]rn2:然后我点击File里面的额exportrn3:选则JAR file然后点击nextrn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名.png][/img]rn4:选中railway后,在点击nextrn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名1.png][/img]rn5:继续nextrn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名2.png][/img]rn6:Main class 中填如主函数,点击finishrn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名3.png][/img]rn7:桌面产生的jar包rn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名4.png][/img]rn可是我双击这个jar包却不会弹出图形用户界面,我在进程里面也看到,双击之后,那jar包只是一出现就没了rn然后我又测试了其他项目,比如这个:rn[img=file://E:\Users\XiaoLong\Desktop\截图,不可删除\QQ截图未命名5.png][/img]rn用上面同样的方法却能成功运行出来,这到底是怎么回事啊??rn希望大家能看到图,不然我白写了! 论坛

如何调用打包后的jar??

01-05

我把一下代码编译成class后打成包DB.jar rn----------------- rnpackage DB; rnimport java.sql.*; rnpublic class connectDB rnString sDBName="dbase"; rnString sDBDriver="org.gjt.mm.mysql.Driver"; rnString sURL="jdbc:mysql://localhost/"+sDBName; rnString sUsername="kafe"; rnString sPassword="81yjuly05d"; rnConnection Conn=null; rnStatement Stmt=null; rnResultSet Rs=null; rnrnpublic void connectDB() rntry rnClass.forName(sDBDriver); rn rncatch(java.lang.ClassNotFoundException e) rnSystem.err.println(e.getMessage()); rn rntry rnConn=DriverManager.getConnection(sURL,sUsername,sPassword); rn rncatch(SQLException e) rnSystem.err.println(e.getMessage()); rn rn rnrnpublic void updateDB(String sSql) rntry rnStmt=Conn.createStatement(); rnStmt.executeUpdate(sSql); rnStmt.close(); rn rncatch(SQLException ex) rnSystem.err.println(ex.getMessage()); rn rn rnrnpublic ResultSet queryDB(String sSql) rntry rnStmt=Conn.createStatement(); rnRs=Stmt.executeQuery(sSql); rnStmt.close(); rn rncatch(SQLException ex) rnSystem.err.println(ex.getMessage()); rn rnreturn Rs; rn rnrnpublic void closeDB() rntry rnConn.close(); rn rncatch(SQLException e) rnSystem.err.println(e.getMessage()); rn rn rnrn rnrn------------------ rnrn我要把这个jar文件放在哪里,我才可以调用java bean。 rnrn我调用的jsp文件如下: rn<%@page import="DB.*,java.sql.*"%> rn rn<% rnDB.connectDB(); rnResultSet rs=DB.queryDB("select * from article"); rnwhile(rs.next()) rnout.println(rs.getString(1)); rn rn%> rnrn我老是调不出来,我哪些地方错了啊?rn谢谢!!rn 论坛

为什么java程序打包jar后窗口的jtree不显示

10-10

在myeclipse里面运行的时候是可以的rn但是打包成jar后就不行了rnrn设置jtree的rn代码是这样的rnrn[code=java]package service;rnrnimport java.awt.event.ActionEvent;rnimport java.awt.event.ActionListener;rnimport java.awt.event.MouseAdapter;rnimport java.awt.event.MouseEvent;rnimport java.io.File;rnimport java.util.Iterator;rnimport java.util.LinkedList;rnimport java.util.Vector;rnrnimport javax.swing.DefaultListModel;rnimport javax.swing.JMenuItem;rnimport javax.swing.JPanel;rnimport javax.swing.JPopupMenu;rnimport javax.swing.JScrollPane;rnimport javax.swing.JTree;rnimport javax.swing.SwingUtilities;rnimport javax.swing.tree.DefaultMutableTreeNode;rnimport javax.swing.tree.TreePath;rnrnimport service.Dto.MyType;rnrnpublic class MyTreernrn private JPanel panel;rn private Dto dto;rn private Play play;rn private FileInput fileinput = null;rn private JScrollPane jscrollTree;rn // 设置树rn private JTree jtree;rn // 设置节点(此节点为跟节点)rn private DefaultMutableTreeNode dmtnRoot = new DefaultMutableTreeNode();rnrn private DefaultMutableTreeNode dmtnLeaf;rnrn private LinkedList treeList;rn private TreePath path;rn private static int num = 0;rn rn JPopupMenu popMenu;rnrn JMenuItem addItem;rn JMenuItem delItem;rnrn rn public MyTree(JPanel panel, Dto dto, Play play) rn this.panel = panel;rn this.dto = dto;rn this.play = play;rn treeList = new LinkedList();rn treeList.add(new DefaultMutableTreeNode("默认列表"));rn treeList.add(new DefaultMutableTreeNode("最近播放"));rn initView();rn setOnlineList();rn popMenu = new JPopupMenu();rn rn addItem = new JMenuItem("添加");rn delItem = new JMenuItem("移除");rn rn popMenu.add(addItem);rn popMenu.add(delItem);rn rn actionListener();rn rn addItem.addActionListener(new ActionListener() rn public void actionPerformed(ActionEvent evt) rn if (fileinput == null)rn fileinput = new FileInput(MusicPlayerFrame.musicplayer);rn fileinput.open();rn File[] files = fileinput.getFiles();rn saveOpenFiles(files);rn setOnlineList();rn rn );rn delItem.addActionListener(new ActionListener() rn public void actionPerformed(ActionEvent e) rn jtree.setSelectionPath(path);rn DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtreern .getLastSelectedPathComponent();rn if (node != null) rn String name = node.toString();rn if (name.equals("默认列表")) rn removeAll();rn else rn removeFile(name);rn rn rn rn );rn rnrn rnrn private void removeAll() rn Vector playlist = dto.getPlayList();rn playlist.clear();rn dto.setCurrentIndex(-1);rn dto.setStop();rn treeList.getLast().removeAllChildren();rn setOnlineList();rn SwingUtilities.invokeLater(new Runnable() rn public void run() rn jtree.updateUI(); rn rn );rn rn rn private boolean checkSame(String name, Vector list) rn for (Iterator iterator = list.iterator(); iterator.hasNext();) rn MyType myType = (MyType) iterator.next();rn if (myType.getFilename().equals(name)) rn return true;rn rn rn return false;rn rn public void removeFile(String name) rn Vector list = dto.getPlayList();rn int k = findFileLoation(name);rn if (k < 0 || k >= list.size()) rn return;rn rn int cur = dto.getCurrentIndex();rn if (cur > k) rn cur--;rn else if (cur == k) rn play.Next();rn dto.setCurrentIndex(cur);rn else rn list.remove(k);rn rn setOnlineList();rn SwingUtilities.invokeLater(new Runnable() rn public void run() rn jtree.updateUI(); rn rn );rn rn rn private void saveOpenFiles(File[] files) rn Vector playlist = dto.getPlayList();rn if (files != null) rn for (File file : files) rn if (file.isDirectory()) rn getDirectoryFiles(file.getAbsolutePath(), playlist);rn rn else if (!checkSame(file.getName().toLowerCase(), playlist)) rn MyType temp = dto.newMyType(file.getName().toLowerCase(),rn file.getAbsolutePath().toLowerCase());rn playlist.add(temp);rn else rnrn rn rn dto.setPlayList(playlist);rn rnrn rn private void getDirectoryFiles(String filepath, Vector playlist) rn num = 0;rn getFiles(filepath, playlist);rn System.out.println(num);rn rn rn private void getFiles(String filePath, Vector playlist) rn File root = new File(filePath);rn File[] files = root.listFiles();rn if (files == null) return;rn for (File file : files) rn if (file.isDirectory()) rn String spath = file.getAbsolutePath();rn int index = spath.indexOf("$RECYCLE.BIN");rn if (index >= 0) rn System.out.println("do not find $RECYCLE.BIN");rn continue;rn rn getFiles(file.getAbsolutePath(), playlist);rn rn if (file.isFile()) rn if (file.getName().endsWith(".mp3") || file.getName().endsWith(".wav")) rn if (!checkSame(file.getName().toLowerCase(), playlist)) rn MyType temp = dto.newMyType(file.getName().toLowerCase(),rn file.getAbsolutePath().toLowerCase());rn playlist.add(temp);rn System.out.println("import " + file.getAbsolutePath());rn num++;rn rn rn rn rn rn rn rn // 视图rn public void initView() rnrn new DefaultListModel();rn panel.setLayout(null);rn jtree = new JTree(dmtnRoot);rn // 设置根节点是否显示rn jtree.setRootVisible(false);rn jtree.putClientProperty("JTree.lineStyle", "None");// 清除线rn //jtree.setShowsRootHandles(true);// 设置图标rn// DefaultTreeCellRenderer cellRenderer=(DefaultTreeCellRenderer)jtree.getCellRenderer();rn// //获取该树的Renderer rn// cellRenderer.setClosedIcon(Img.CLOSE);rn// //关闭打开图标 rn// cellRenderer.setOpenIcon(Img.MIN);rn// //设置展开图标rn //设置单击打开rn jtree.setToggleClickCount(1);rn for (Iterator iterator = treeList.iterator(); rn iterator.hasNext();) rn dmtnRoot.add(iterator.next());rnrn rnrn jscrollTree = new JScrollPane(jtree);rn jscrollTree.setBounds(0, 110, 250, 320);rn panel.add(jscrollTree);rn rnrn rn public void actionListener() rn rn jtree.addMouseListener(new MouseAdapter() rn @Overridern public void mouseClicked(MouseEvent e) rnrn int count = jtree.getRowForLocation(e.getX(), e.getY());rnrn if (e.getButton() != 3 && count != -1) rn String strFriendUsername = jtreern .getLastSelectedPathComponent().toString();rn if (e.getClickCount() == 2 && count != 0rn && check(strFriendUsername)) rn if (jtree.isRowSelected(jtree.getRowForLocation(rn e.getX(), e.getY()))) rn System.out.println("你双击了:" + strFriendUsername);rn int k = findFileLoation(strFriendUsername);rn if (k >= 0 && k < dto.getPlayList().size()) rn dto.setCurrentIndex(k);rn rn play.playSelect();rn rn rn rn if (e.getButton() == 3) rn path = jtree.getPathForLocation(e.getX(), e.getY()); // 关键是这个方法的使用rn if (path == null) rn return;rn rn rn jtree.setSelectionPath(path);rn DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtreern .getLastSelectedPathComponent();rn if (node != null) rn if (node.equals(treeList.getLast())) rn return;rn else if (node.getParent().equals(treeList.getLast())) rn return;rn rn popMenu.show(jtree, e.getX(), e.getY());rn rn rn rn );rn rnrn rn rn rnrn private int findFileLoation(String name) rn Vector playList = dto.getPlayList();rn for (int i = 0; i < playList.size(); i++) rn if (playList.elementAt(i).getFilename().equals(name)) rn return i;rn rn rn return -1;rn rnrn private boolean check(String name) rn for (Iterator iterator = treeList.iterator(); iteratorrn .hasNext();) rn DefaultMutableTreeNode type = iterator.next();rn if (type.toString().equals(name)) rn return false;rn rn rn return true;rn rnrn // 设置在线列表rn public void setOnlineList() rn // TODOrn treeList.get(0).removeAllChildren();rn for (int i = 0; i < dto.getPlayList().size(); i++) rn add(dto.getPlayList().elementAt(i), treeList.get(0));rn rn //jtree.updateUI();rn SwingUtilities.invokeLater(new Runnable() rn public void run() rn jtree.updateUI(); rn rn );rn rnrn public void add(MyType elem, DefaultMutableTreeNode dmtList) rn dmtnLeaf = new DefaultMutableTreeNode(elem.getFilename());rn dmtList.add(dmtnLeaf);rn rn rn public void addPlayHistory(String name) rn LinkedList list = dto.getPlayHistory();rn while (list.contains(name)) rn list.remove(name);rn rn list.add(name);rn treeList.get(1).removeAllChildren();rn for (int i = list.size() - 1; i >= 0; i--) rn treeList.get(1).add(new DefaultMutableTreeNode(list.get(i)));rn rn dto.setPlayHistory(list);rn //jtree.updateUI();rn SwingUtilities.invokeLater(new Runnable() rn public void run() rn jtree.updateUI(); rn rn );rn rnrn rn rn[/code]rnrnrn实在是不知道为什么- -、 又或者是要去继承JTree才行么。。。 论坛

没有更多推荐了,返回首页