Java .jar没有执行与Eclipse中相同的操作
我从Eclipse应用程序创建了一个.jar。 所以我要导出->JAR文件->选择我的包+库->定义我的主类 我的程序使用RxTx库 这是我的主机:Java .jar没有执行与Eclipse中相同的操作,java,eclipse,jar,path,rxtx,Java,Eclipse,Jar,Path,Rxtx,我从Eclipse应用程序创建了一个.jar。 所以我要导出->JAR文件->选择我的包+库->定义我的主类 我的程序使用RxTx库 这是我的主机: package Main; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import java.awt.BorderLayout; ... public class MainFrame{ public final static String PathLogo1 =
package Main;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.awt.BorderLayout;
...
public class MainFrame{
public final static String PathLogo1 = "A:/ICOMSSOFT/IVT Corporation/BlueSoleil/icon-logo.png";
public final static String PathLogo2 = "A:/ICOMSSOFT/IVT Corporation/BlueSoleil/ICOMS LOGO.jpg";
public final static String PathBlueSoleilIcon = "A:/ICOMSSOFT/IVT Corporation/BlueSoleil/BluetoothImage.png";
protected static final JComboBox<String> JB_ChoixPortCom = null;
static JButton JB_Connect;
static String ChoixPortCom = null;
//**********************************************************************************
//************************ RxTx Variable *******************************************
//**********************************************************************************
static CommPortIdentifier serialPortId;
static Enumeration<?> enumComm;
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream;
static Boolean SerialPortCheck = false;
static int baudrate = 9600;
static int dataBits = SerialPort.DATABITS_8;
static int stopBits = SerialPort.STOPBITS_1;
static int parity = SerialPort.PARITY_NONE;
JPanel panel = new JPanel (new GridBagLayout());
JPanel panelSetup = new JPanel(new GridBagLayout());
JPanel panelCommunication = new JPanel(new GridBagLayout());
static JComboBox<String> selection = new JComboBox<String>();
JButton open = new JButton("Open");
JButton close = new JButton("Close");
JButton actualise = new JButton("Actualisé");
JButton envoie = new JButton("Message envoie");
JTextField message = new JTextField();
JCheckBox echo = new JCheckBox("Echo");
static JTextArea recoit = new JTextArea();
JScrollPane recoitJScrollPane = new JScrollPane();
//**********************************************************************************
//**********************************************************************************
//**********************************************************************************
public static void FenetrePrincipal() {
final JFrame JF_Principal = new JFrame("ICOMSSOFT");
JF_Principal.setVisible(true);
JF_Principal.setSize(1000,900);
JF_Principal.setLocationRelativeTo(null);
JF_Principal.setResizable(false);
JF_Principal.setIconImage(Toolkit.getDefaultToolkit().getImage(PathLogo1));
//******************************************************************************************
//******************************** JPANEL NORTH ********************************************
//******************************************************************************************
JPanel JP_North = new JPanel(); // container du BorderLayout.North
JP_North.setPreferredSize(new Dimension(600,150));
JPanel JP_Logo = new JPanel(); // container du JLabel
JP_Logo.setBackground(Color.white);
JLabel JL_Logo = new JLabel(new ImageIcon(PathLogo2));
JP_Logo.add(JL_Logo);
JP_North.add(JP_Logo);
JP_North.setBackground(Color.white);
JP_North.setVisible(true);
//******************************************************************************************
//******************************** JPANEL Center ********************************************
//******************************************************************************************
final JPanel JP_Center = new JPanel();
JP_Center.setPreferredSize(new Dimension(600,700)); // 900- 600 = 300 left
JP_Center.setBackground(Color.white);
final JPanel JP_ChoixConnection = new JPanel();
JP_ChoixConnection.setBorder(BorderFactory.createTitledBorder("Choix Connection : "));
JP_ChoixConnection.setPreferredSize(new Dimension(540, 175));
JP_ChoixConnection.setBackground(Color.white);
ImageIcon pic = new ImageIcon(PathBlueSoleilIcon);
JButton JB_LaunchBlueSoleil = new JButton(pic);
JB_LaunchBlueSoleil.setPreferredSize(new Dimension(100, 135));
JP_ChoixConnection.add(JB_LaunchBlueSoleil);
JP_Center.add(JP_ChoixConnection);
//******************************************************************************************
//******************************** JPANEL South ********************************************
//******************************************************************************************
JPanel JP_South = new JPanel();
JP_South.setBackground(Color.white);
JP_South.setPreferredSize(new Dimension(600,50));
JPanel JP_Bouton = new JPanel();
JP_Bouton.setBackground(Color.white);
JButton JB_Quit = new JButton("Quitter");
JB_Quit.setPreferredSize(new Dimension(85, 35));
JP_South.add(JP_Bouton);
JP_Bouton.add(JB_Quit);
JF_Principal.getContentPane().add(JP_North, BorderLayout.NORTH);
JF_Principal.getContentPane().add(JP_Center, BorderLayout.CENTER);
JF_Principal.getContentPane().add(JP_South, BorderLayout.SOUTH);
JF_Principal.setVisible(true);
//******************************************************************************************
//******************************** Action Listener *****************************************
//******************************************************************************************
JB_LaunchBlueSoleil.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try {
Bluetooth.Launch(Bluetooth.GetPath());
} catch (IOException e) {
e.printStackTrace();
}
String[] ListPortCom = rxtx.GetPortCom();
int nbrPort = Integer.parseInt(ListPortCom[99]); // String -> int
final JPanel JP_ChoixPortCom = new JPanel();
JP_ChoixPortCom.setBorder(BorderFactory.createTitledBorder("Choix Port Com : "));
JP_ChoixPortCom.setPreferredSize(new Dimension(500, 100));
JP_ChoixPortCom.setBackground(Color.white);
final JComboBox<String> JB_ChoixPortCom = new JComboBox<String>();
for(int i = 0; i < nbrPort; i++) JB_ChoixPortCom.addItem(ListPortCom[i]);
JB_Connect = new JButton("Connect");
JP_ChoixPortCom.add(JB_ChoixPortCom);
JP_ChoixPortCom.add(JB_Connect);
JP_Center.add(JP_ChoixPortCom);
System.out.println("JP_ChoixConnection -> bye bye");
JP_ChoixConnection.setVisible(false);
CommunicationBT.BT(JP_Center);
JB_ChoixPortCom.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e) {
ChoixPortCom = (String)JB_ChoixPortCom.getSelectedItem();
}});
JB_Connect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if (ChoixPortCom.equals(null) == true ) JOptionPane.showMessageDialog(null, "Choose Port COM");
else rxtx.CheckPort(ChoixPortCom);
}
});
}
});
JB_Quit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
JF_Principal.dispose();
}
});
}
public static void main(String[] args) throws IOException, InterruptedException {
FenetrePrincipal();
}
packagemain;
输入gnu.io.CommPortIdentifier;
导入gnu.io.SerialPort;
导入java.awt.BorderLayout;
...
公共类主机{
公共最终静态字符串PathLogo1=“A:/icomsoft/IVT Corporation/BlueSoleil/icon logo.png”;
公共最终静态字符串PathLogo2=“A:/icomsoft/IVT Corporation/BlueSoleil/ICOMS LOGO.jpg”;
公共最终静态字符串PathBlueSoleilIcon=“A:/icomsoft/IVT Corporation/BlueSoleil/BluetoothImage.png”;
受保护的静态最终JComboBox JB_ChoixPortCom=null;
静态按钮接线盒;
静态字符串ChoixPortCom=null;
//**********************************************************************************
//************************RxTx变量*******************************************
//**********************************************************************************
静态CommPortIdentifier serialPortId;
静态枚举枚举通信;
静态串口串口;
静态输出流输出流;
静态输入流输入流;
静态布尔SerialPortCheck=false;
静态整数波特率=9600;
静态int-dataBits=SerialPort.dataBits_8;
静态int stopBits=SerialPort.stopBits_1;
静态int奇偶校验=串行端口。奇偶校验\u无;
JPanel panel=newjpanel(newgridbagloayout());
JPanel panelSetup=newjpanel(newgridbagloayout());
JPanel panelCommunication=newjpanel(newgridbaglayout());
静态JComboBox选择=新建JComboBox();
JButton open=新JButton(“open”);
JButton close=新JButton(“close”);
JButton实现=新的JButton(“实现”);
JButton envoie=新JButton(“消息envoie”);
JTextField message=新的JTextField();
JCheckBox echo=新的JCheckBox(“echo”);
静态JTextArea recoit=新JTextArea();
JScrollPane recoitJScrollPane=新的JScrollPane();
//**********************************************************************************
//**********************************************************************************
//**********************************************************************************
公共静态无效FenetrePrincipal(){
最终JFrame JF_Principal=新JFrame(“ICOMSoft”);
JF_Principal.setVisible(真);
JF_负责人设置尺寸(1000900);
JF_Principal.setLocationRelativeTo(空);
JF_Principal.SetResizeable(假);
JF_Principal.setIconImage(Toolkit.getDefaultToolkit().getImage(PathLogo1));
//******************************************************************************************
//********************************杰帕内尔北酒店********************************************
//******************************************************************************************
JPanel JP_North=new JPanel();//容器du BorderLayout.North
JP_North.setPreferredSize(新尺寸(600150));
JPanel JP_Logo=new JPanel();//容器du JLabel
JP_标志。背景(颜色。白色);
JLabel JL_Logo=新JLabel(新图像图标(路径logo2));
JP_Logo.add(JL_Logo);
JP_North.add(JP_徽标);
JP_North.挫折地(颜色:白色);
JP_North.setVisible(真);
//******************************************************************************************
//********************************杰帕内尔中心********************************************
//******************************************************************************************
最终JPanel JP_中心=新JPanel();
JP_Center.setPreferredSize(新尺寸(600700));//900-600=300左
JP_中心。背景(颜色。白色);
final JPanel JP_ChoixConnection=new JPanel();
JP_ChoixConnection.setboorder(BorderFactory.createTitledBorder(“Choix连接:”);
JP_ChoixConnection.setPreferredSize(新维度(540175));
JP_ChoixConnection.setBackground(颜色:白色);
ImageIcon pic=新的ImageIcon(PathBlueSoleilIcon);
JButton JB_LaunchBlueSoleil=新JButton(图);
JB_LaunchBlueSoleil.setPreferredSize(新尺寸(100135));
JP_ChoixConnection.add(JB_LaunchBlueSoleil);
JP_Center.add(JP_ChoixConnection);
//******************************************************************************************
//********************************杰帕内尔南部********************************************
//******************************************************************************************
JPanel JP_South=新JPanel();
JP_South.挫折地(颜色:白色);
JP_South.setPreferredSize(新尺寸(600,50));
JPanel JP_Bouton=新的JPanel();
JP_Bouton.挫折背景(颜色:白色);
JButton JB_Quit=新的JButton(“退出者”);
JB_Quit.setPreferredSize(新尺寸(85,35));
南太平绅士(JP_Bouton);
JP_Bouton.add(JB_Quit);
JF_Principal.getContentPane().add(JP_North,BorderLayout.North);
JF_Principal.getContentPane().add(JP_Center,BorderLayout.Center);
JF_Principal.getContentPane().add(JP_South,BorderLayout.South);
JF_Principal.setVisible(真);
//******************************************************************************************
//********************************动作监听器*****************************************
//******************************************************************************************
JB_LaunchBlueSoleil.addActionListener(新的ActionListener(){
已执行的公共无效操作(操作事件arg0){
试一试{
Bluetooth.Launch(Bluetooth.GetPath());
}捕获(IOE异常){
e、 printStackTrace();
}
字符串[]ListPortCom=rxtx.GetPortCom();
int nbrPort=Integer.parseInt(ListPortCom[99]);//字符串->int
final JPanel JP_ChoixPortCom=new JPanel();
JP_ChoixPortCom.setboorder(BorderFactory.createTitledBorder(“Choix Por
package Main;
import gnu.io.*; // RXTX
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
public class rxtx {
static CommPortIdentifier serialPortId;
static Enumeration<?> enumComm;
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream;
int baudrate = 9600;
int dataBits = SerialPort.DATABITS_8;
int stopBits = SerialPort.STOPBITS_1;
int parity = SerialPort.PARITY_NONE;
static Boolean SerialPortCheck = false;
public static String[] GetPortCom(){
String[] List = new String[100]; // List[99] = nbrPort
int nbrPort = 0;
CommPortIdentifier serialPortId;
Enumeration<?> enumComm;
enumComm = CommPortIdentifier.getPortIdentifiers();
while (enumComm.hasMoreElements()) {
serialPortId = (CommPortIdentifier) enumComm.nextElement();
if(serialPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//System.out.println(serialPortId.getName());
List[nbrPort] = serialPortId.getName();
nbrPort++;
}
List[99] = Integer.toString(nbrPort); // Int -> String
}
for (int i = 0; i < nbrPort; i++) {
System.out.println(List[i]);
}
return List;
}
public static boolean CheckPort(String portName){
boolean foundPort = false;
if (SerialPortCheck != false) {
System.out.println("Serial Port déjà ouvert");
return true;
}
enumComm = CommPortIdentifier.getPortIdentifiers();
while(enumComm.hasMoreElements()) {
serialPortId = (CommPortIdentifier) enumComm.nextElement();
if (portName.contentEquals(serialPortId.getName())) {
foundPort = true;
break;
}
}
if (foundPort != true) {
System.out.println("Serialport pas trouver: " + portName);
return false;
}
try {
serialPort = (SerialPort) serialPortId.open("Ouvert + Envoie", 500);
} catch (PortInUseException e) {
System.out.println("Port -> OK");
}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
System.out.println("Probleme en OutputStream");
}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {
System.out.println("Probleme en InputStream");
}
SerialPortCheck = true;
return true;
}