我正在开发一个 GUI 客户端,它将成为一个独立的应用程序,充当 MySQL 数据库后端的前端。我已经为客户端完成了所有的逻辑和编码,但我无法将项目导出到可运行的 .jar 文件。
我有 Eclipse 生成的 manifest.txt,它位于 META-INF 文件夹中。
这是我的主要方法:
package binaparts.main;
import binaparts.gui.*;
public class Main{
public static void main(String[] args){
MainFrames m = new MainFrames();
m.displayGUI();
}
}
这是 MainFrames 类:
package binaparts.gui;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ItemListener;
import java.sql.*;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import org.json.JSONArray;
import org.json.JSONObject;
import binaparts.dao.*;
import binaparts.properties.ConfigurationManager;
public class MainFrames extends JFrame
{
private MainPanel main;
private CreatePanel create;
private UpdatePanel update;
private FindPanel find;
private SettingsPanel settings;
private ManageUsersPanel Manage;
JFrame frame = new JFrame("Main Menu:");
static final String configFilePath = "META-INF/config.properties";
DBConnect con = new DBConnect();
ConfigurationManager config = null;
public void run(){
displayGUI();
}
public void displayGUI()
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
contentPane.setLayout(new CardLayout());
main = new MainPanel(contentPane);
create = new CreatePanel(contentPane);
update = new UpdatePanel(contentPane);
find = new FindPanel(contentPane);
settings = new SettingsPanel(contentPane);
Manage = new ManageUsersPanel(contentPane);
contentPane.add(main, "Main Menu");
contentPane.add(create, "Create Part");
contentPane.add(update, "Update Part");
contentPane.add(find, "Find Part");
contentPane.add(settings, "Settings");
contentPane.add(Manage, "Manage Users");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int height = screenSize.height;
int width = screenSize.width;
frame.setResizable(false);
frame.setSize(width/2, height/2);
frame.setLocationRelativeTo(null);
frame.setSize(700, 580);
frame.setContentPane(contentPane);
frame.setVisible(true);
}
class MainPanel extends JPanel{Contains code for that frame}
class MainPanel extends JPanel{Contains code for that frame}
class CreatePanel extends JPanel{Contains code for that frame}
class UpdatePanel extends JPanel{Contains code for that frame}
class FindPanel extends JPanel{Contains code for that frame}
class SettingsPanel extends JPanel{Contains code for that frame}
class ManageUsersPanel extends JPanel{Contains code for that frame}
}
我没有包含每个面板的代码,以免造成混乱。还有一些其他类用于管理配置属性和数据库连接,它们工作得很好。
我的问题是:我的主要方法/displayGUI 交互或创建 jar 的过程是否有问题?
提前感谢您的帮助!
我运行了 cmd java -jar my.jar 并得到了
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Danny>cd desktop
C:\Users\Danny\Desktop>cd executable
C:\Users\Danny\Desktop\Executable>java -jar BinaPartsManager.jar
java.io.FileNotFoundException: META-INF\config.properties (The system cannot fin
d the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at binaparts.properties.ConfigurationManager.save(ConfigurationManager.j
ava:41)
at binaparts.properties.ConfigurationManager.<init>(ConfigurationManager
.java:21)
at binaparts.dao.DBConnect.verifyUser(DBConnect.java:87)
at binaparts.gui.MainFrames$MainPanel.setStatus(MainFrames.java:110)
at binaparts.gui.MainFrames$MainPanel.<init>(MainFrames.java:137)
at binaparts.gui.MainFrames.displayGUI(MainFrames.java:66)
at binaparts.main.RunProgram.main(RunProgram.java:10)
java.lang.NullPointerException
at binaparts.dao.DBConnect.close(DBConnect.java:21)
at binaparts.gui.MainFrames$MainPanel.setStatus(MainFrames.java:127)
at binaparts.gui.MainFrames$MainPanel.<init>(MainFrames.java:137)
at binaparts.gui.MainFrames.displayGUI(MainFrames.java:66)
at binaparts.main.RunProgram.main(RunProgram.java:10)
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at binaparts.gui.MainFrames$MainPanel.<init>(MainFrames.java:147)
at binaparts.gui.MainFrames.displayGUI(MainFrames.java:66)
at binaparts.main.RunProgram.main(RunProgram.java:10)
我将 config.properties 文件存储在 META-INF 文件夹中。虽然它在 IDE 中运行良好。