直接在Eclipse中运行源码即可。为什么 Jar 文件将停止 运行 并且控制台中没有异常显示?

Directly, run source code in Eclipse is OK. Why the Jar file will stop run and no exception show in console?

我非常努力地在 Whosebug 和 Google 中找到答案。我也尝试了很多方法来测试我的程序但都失败了。 我的问题如下: 我尝试在 PC 端编写服务器程序并与另一台机器上的客户端通信。我可以 运行 Eclipse IDE 中的整个程序,没问题。很奇怪,我不能运行同一台PC上的Jar文件。

由于没有报错信息,我猜Jar文件打包的过程可能是关键点。我尝试测试所有可能的方式来导出 jar 文件,并修改不同种类的 MENIFEST 文件来测试程序。

程序如下:

package idv.xml.serverclient;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerFactoryConfigurationError;

import org.jdom2.Document;
import org.jdom2.output.XMLOutputter;
//import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class Server1 extends Thread {

    private Socket mySocket;
    private ServerSocket myServer;
    private int intPort;
    private ReadFile readFile;
    private ReadData ReadData;
    private String isContinue = "0";
    WriteFile wftolog = new WriteFile();

    public Server1() {
        // 預設建構子
    }

    public Server1(int intPort) {
        // super();
        this.intPort = intPort;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        super.run();
        while (true) {
            readFile = new ReadFile();

            try {
                myServer = new ServerSocket(intPort);
                System.out.println("Server started at port:" + intPort);
                // 等待Client的連接

                System.out.println("Waiting for Client Connet.....");
                wftolog.addLog("Waiting for Client Connet.....");
                // 設置監聽器等待client的連線
                mySocket = myServer.accept();

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        try {
                            SimpleAttributeSet keyWord = new SimpleAttributeSet();
                            StyleConstants.setForeground(keyWord, Color.RED);
                            StyleConstants.setBackground(keyWord, Color.YELLOW);
                            StyleConstants.setBold(keyWord, true);
                            HMI_Window.doc.insertString(0, "工作中........\n", keyWord);

                        } catch (BadLocationException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                    }

                });
            } catch (NullPointerException e) {
                e.getStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println("Accept Client " + mySocket);
            System.out.println("------Connection Created--------");
            wftolog.addLog("連線成功, 工作中........");
            if (ReadFile.isPTP == 0) {
                System.out.println("進去讀LIN資料串");
                readBufferLIN();
                wftolog.addLog("傳輸LIN資料成功。");
            } else {
                //確認是否是最後一個檔案
                if (ReadFile.fileCounter == (idv.xml.serverclient.ReadData.fileNumber)) {
                    isContinue = "1";
                }
                System.out.println("進去讀PTP資料串");
                readBufferPTP();
                wftolog.addLog("傳輸PTP資料成功。");
                System.out.println("readFile.fileCounter="+(ReadFile.fileCounter-1)+";readData.fileNumber="+(idv.xml.serverclient.ReadData.fileNumber - 1));
                if (ReadFile.fileCounter == (idv.xml.serverclient.ReadData.fileNumber)) {
                    break;
                }
            }
            // 完成連線
            System.out.println("success");
            wftolog.addLog("完成資料傳輸");
        }
    }

    public void readBufferPTP() {

        // ----------- XML傳送資料 (JDOM)-----------
        try {
            // 生成Document物件
            Document docJDOM = new Document();
            XMLOutputter XMLOut = new XMLOutputter();
            // 生成XML字符串,即XML文件的内容,包含很多换行符
            String xmlString = XMLOut.outputString(docJDOM);
            xmlString = "<Sensor>"+ "\n"
                    +   "<Message>Example message</Message>"+ "\n"
                    +   "<Positions>"+ "\n"
                    + "<Current A1=\"" + readFile.A1[0] + "\"" + " " 
                    + "A2=\"" + readFile.A2[0] + "\"" + " " 
                    + "A3=\"" + readFile.A3[0] + "\"" + " " 
                    + "A4=\"" + readFile.A4[0] + "\"" + " " 
                    + "A5=\"" + readFile.A5[0] + "\"" + " " 
                    + "A6=\"" + readFile.A6[0] + "\"" + " " 
                    + "E1=\"" + readFile.E1[0] + "\"" + " "
                    + "E2=\"" + readFile.E2[0] + "\"" + " " 
                    + "E3=\"" + readFile.E3[0] + "\"" + " " 
                    + "E4=\"" + readFile.E4[0] + "\"" + " " 
                    + "E5=\"" + readFile.E5[0] + "\"" + " " 
                    + "E6=\"" + readFile.E6[0]+ "\""  + "/>" + "\n"
                    +   "<Before>"+ "\n"
                    +   "<X>0.9842</X>"+ "\n"
                    +   "</Before>"+ "\n"
                    +   "</Positions>"+ "\n"
                    +   "<Nmb>" + String.valueOf(readFile.lineNumber) + "</Nmb>" + "\n"
                    +   "<Status>"+ "\n"
                    +   "<IsActive>1</IsActive>"+ "\n"
                    +   "</Status>"+ "\n"
                    +   "<Read>"+ "\n"
                    +   "<xyzabc1 X=\""+ReadData.x[0]+"\" Y=\""+ReadData.y[0]+"\" Z=\""+ReadData.z[0]+"\" A=\""+ReadData.a[0]+"\" B=\""+ReadData.b[0]+"\" C=\""+ReadData.c[0]+"\"/>"+ "\n"
                    +   "<xyzabc2 X=\""+ReadData.x[1]+"\" Y=\""+ReadData.y[1]+"\" Z=\""+ReadData.z[1]+"\" A=\""+ReadData.a[1]+"\" B=\""+ReadData.b[1]+"\" C=\""+ReadData.c[1]+"\"/>"+ "\n"
                    +   "<xyzabc3 X=\""+ReadData.x[2]+"\" Y=\""+ReadData.y[2]+"\" Z=\""+ReadData.z[2]+"\" A=\""+ReadData.a[2]+"\" B=\""+ReadData.b[2]+"\" C=\""+ReadData.c[2]+"\"/>"+ "\n"
                    +   "<xyzabc4 X=\""+ReadData.x[3]+"\" Y=\""+ReadData.y[3]+"\" Z=\""+ReadData.z[3]+"\" A=\""+ReadData.a[3]+"\" B=\""+ReadData.b[3]+"\" C=\""+ReadData.c[3]+"\"/>"+ "\n"
                    +   "<xyzabc5 X=\""+ReadData.x[4]+"\" Y=\""+ReadData.y[4]+"\" Z=\""+ReadData.z[4]+"\" A=\""+ReadData.a[4]+"\" B=\""+ReadData.b[4]+"\" C=\""+ReadData.c[4]+"\"/>"+ "\n"
                    +   "<xyzabc6 X=\""+ReadData.x[5]+"\" Y=\""+ReadData.y[5]+"\" Z=\""+ReadData.z[5]+"\" A=\""+ReadData.a[5]+"\" B=\""+ReadData.b[5]+"\" C=\""+ReadData.c[5]+"\"/>"+ "\n"
                    +   "<xyzabc7 X=\""+ReadData.x[6]+"\" Y=\""+ReadData.y[6]+"\" Z=\""+ReadData.z[6]+"\" A=\""+ReadData.a[6]+"\" B=\""+ReadData.b[6]+"\" C=\""+ReadData.c[6]+"\"/>"+ "\n"
                    +   "<xyzabc8 X=\""+ReadData.x[7]+"\" Y=\""+ReadData.y[7]+"\" Z=\""+ReadData.z[7]+"\" A=\""+ReadData.a[7]+"\" B=\""+ReadData.b[7]+"\" C=\""+ReadData.c[7]+"\"/>"+ "\n"
                    +   "<xyzabc9 X=\""+ReadData.x[8]+"\" Y=\""+ReadData.y[8]+"\" Z=\""+ReadData.z[8]+"\" A=\""+ReadData.a[8]+"\" B=\""+ReadData.b[8]+"\" C=\""+ReadData.c[8]+"\"/>"+ "\n"
                    +   "<xyzabc10 X=\""+ReadData.x[9]+"\" Y=\""+ReadData.y[9]+"\" Z=\""+ReadData.z[9]+"\" A=\""+ReadData.a[9]+"\" B=\""+ReadData.b[9]+"\" C=\""+ReadData.c[9]+"\"/>"+ "\n"
                    +   "<xyzabc11 X=\""+ReadData.x[10]+"\" Y=\""+ReadData.y[10]+"\" Z=\""+ReadData.z[10]+"\" A=\""+ReadData.a[10]+"\" B=\""+ReadData.b[10]+"\" C=\""+ReadData.c[10]+"\"/>"+ "\n"
                    +   "<xyzabc12 X=\""+ReadData.x[11]+"\" Y=\""+ReadData.y[11]+"\" Z=\""+ReadData.z[11]+"\" A=\""+ReadData.a[11]+"\" B=\""+ReadData.b[11]+"\" C=\""+ReadData.c[11]+"\"/>"+ "\n"
                    +   "<xyzabc13 X=\""+ReadData.x[12]+"\" Y=\""+ReadData.y[12]+"\" Z=\""+ReadData.z[12]+"\" A=\""+ReadData.a[12]+"\" B=\""+ReadData.b[12]+"\" C=\""+ReadData.c[12]+"\"/>"+ "\n"
                    +   "<xyzabc14 X=\""+ReadData.x[13]+"\" Y=\""+ReadData.y[13]+"\" Z=\""+ReadData.z[13]+"\" A=\""+ReadData.a[13]+"\" B=\""+ReadData.b[13]+"\" C=\""+ReadData.c[13]+"\"/>"+ "\n"
                    +   "<xyzabc15 X=\""+ReadData.x[14]+"\" Y=\""+ReadData.y[14]+"\" Z=\""+ReadData.z[14]+"\" A=\""+ReadData.a[14]+"\" B=\""+ReadData.b[14]+"\" C=\""+ReadData.c[14]+"\"/>"+ "\n"
                    +   "<xyzabc16 X=\""+ReadData.x[15]+"\" Y=\""+ReadData.y[15]+"\" Z=\""+ReadData.z[15]+"\" A=\""+ReadData.a[15]+"\" B=\""+ReadData.b[15]+"\" C=\""+ReadData.c[15]+"\"/>"+ "\n"
                    +   "<xyzabc17 X=\""+ReadData.x[16]+"\" Y=\""+ReadData.y[16]+"\" Z=\""+ReadData.z[16]+"\" A=\""+ReadData.a[16]+"\" B=\""+ReadData.b[16]+"\" C=\""+ReadData.c[16]+"\"/>"+ "\n"
                    +   "<xyzabc18 X=\""+ReadData.x[17]+"\" Y=\""+ReadData.y[17]+"\" Z=\""+ReadData.z[17]+"\" A=\""+ReadData.a[17]+"\" B=\""+ReadData.b[17]+"\" C=\""+ReadData.c[17]+"\"/>"+ "\n"
                    +   "<xyzabc19 X=\""+ReadData.x[18]+"\" Y=\""+ReadData.y[18]+"\" Z=\""+ReadData.z[18]+"\" A=\""+ReadData.a[18]+"\" B=\""+ReadData.b[18]+"\" C=\""+ReadData.c[18]+"\"/>"+ "\n"
                    +   "<xyzabc20 X=\""+ReadData.x[19]+"\" Y=\""+ReadData.y[19]+"\" Z=\""+ReadData.z[19]+"\" A=\""+ReadData.a[19]+"\" B=\""+ReadData.b[19]+"\" C=\""+ReadData.c[19]+"\"/>"+ "\n"
                    +   "<xyzabc21 X=\""+ReadData.x[20]+"\" Y=\""+ReadData.y[20]+"\" Z=\""+ReadData.z[20]+"\" A=\""+ReadData.a[20]+"\" B=\""+ReadData.b[20]+"\" C=\""+ReadData.c[20]+"\"/>"+ "\n"
                    +   "<xyzabc22 X=\""+ReadData.x[21]+"\" Y=\""+ReadData.y[21]+"\" Z=\""+ReadData.z[21]+"\" A=\""+ReadData.a[21]+"\" B=\""+ReadData.b[21]+"\" C=\""+ReadData.c[21]+"\"/>"+ "\n"
                    +   "<xyzabc23 X=\""+ReadData.x[22]+"\" Y=\""+ReadData.y[22]+"\" Z=\""+ReadData.z[22]+"\" A=\""+ReadData.a[22]+"\" B=\""+ReadData.b[22]+"\" C=\""+ReadData.c[22]+"\"/>"+ "\n"
                    +   "<xyzabc24 X=\""+ReadData.x[23]+"\" Y=\""+ReadData.y[23]+"\" Z=\""+ReadData.z[23]+"\" A=\""+ReadData.a[23]+"\" B=\""+ReadData.b[23]+"\" C=\""+ReadData.c[23]+"\"/>"+ "\n"
                    +   "<xyzabc25 X=\""+ReadData.x[24]+"\" Y=\""+ReadData.y[24]+"\" Z=\""+ReadData.z[24]+"\" A=\""+ReadData.a[24]+"\" B=\""+ReadData.b[24]+"\" C=\""+ReadData.c[24]+"\"/>"+ "\n"
                    +   "<xyzabc26 X=\""+ReadData.x[25]+"\" Y=\""+ReadData.y[25]+"\" Z=\""+ReadData.z[25]+"\" A=\""+ReadData.a[25]+"\" B=\""+ReadData.b[25]+"\" C=\""+ReadData.c[25]+"\"/>"+ "\n"
                    +   "<xyzabc27 X=\""+ReadData.x[26]+"\" Y=\""+ReadData.y[26]+"\" Z=\""+ReadData.z[26]+"\" A=\""+ReadData.a[26]+"\" B=\""+ReadData.b[26]+"\" C=\""+ReadData.c[26]+"\"/>"+ "\n"
                    +   "<xyzabc28 X=\""+ReadData.x[27]+"\" Y=\""+ReadData.y[27]+"\" Z=\""+ReadData.z[27]+"\" A=\""+ReadData.a[27]+"\" B=\""+ReadData.b[27]+"\" C=\""+ReadData.c[27]+"\"/>"+ "\n"
                    +   "<xyzabc29 X=\""+ReadData.x[28]+"\" Y=\""+ReadData.y[28]+"\" Z=\""+ReadData.z[28]+"\" A=\""+ReadData.a[28]+"\" B=\""+ReadData.b[28]+"\" C=\""+ReadData.c[28]+"\"/>"+ "\n"
                    +   "<xyzabc30 X=\""+ReadData.x[29]+"\" Y=\""+ReadData.y[29]+"\" Z=\""+ReadData.z[29]+"\" A=\""+ReadData.a[29]+"\" B=\""+ReadData.b[29]+"\" C=\""+ReadData.c[29]+"\"/>"+ "\n"
                    +   "<xyzabc31 X=\""+ReadData.x[30]+"\" Y=\""+ReadData.y[30]+"\" Z=\""+ReadData.z[30]+"\" A=\""+ReadData.a[30]+"\" B=\""+ReadData.b[30]+"\" C=\""+ReadData.c[30]+"\"/>"+ "\n"
                    +   "<xyzabc32 X=\""+ReadData.x[31]+"\" Y=\""+ReadData.y[31]+"\" Z=\""+ReadData.z[31]+"\" A=\""+ReadData.a[31]+"\" B=\""+ReadData.b[31]+"\" C=\""+ReadData.c[31]+"\"/>"+ "\n"
                    +   "<xyzabc33 X=\""+ReadData.x[32]+"\" Y=\""+ReadData.y[32]+"\" Z=\""+ReadData.z[32]+"\" A=\""+ReadData.a[32]+"\" B=\""+ReadData.b[32]+"\" C=\""+ReadData.c[32]+"\"/>"+ "\n"
                    +   "<xyzabc34 X=\""+ReadData.x[33]+"\" Y=\""+ReadData.y[33]+"\" Z=\""+ReadData.z[33]+"\" A=\""+ReadData.a[33]+"\" B=\""+ReadData.b[33]+"\" C=\""+ReadData.c[33]+"\"/>"+ "\n"
                    +   "<xyzabc35 X=\""+ReadData.x[34]+"\" Y=\""+ReadData.y[34]+"\" Z=\""+ReadData.z[34]+"\" A=\""+ReadData.a[34]+"\" B=\""+ReadData.b[34]+"\" C=\""+ReadData.c[34]+"\"/>"+ "\n"
                    +   "<xyzabc36 X=\""+ReadData.x[35]+"\" Y=\""+ReadData.y[35]+"\" Z=\""+ReadData.z[35]+"\" A=\""+ReadData.a[35]+"\" B=\""+ReadData.b[35]+"\" C=\""+ReadData.c[35]+"\"/>"+ "\n"
                    +   "<xyzabc37 X=\""+ReadData.x[36]+"\" Y=\""+ReadData.y[36]+"\" Z=\""+ReadData.z[36]+"\" A=\""+ReadData.a[36]+"\" B=\""+ReadData.b[36]+"\" C=\""+ReadData.c[36]+"\"/>"+ "\n"
                    +   "<xyzabc38 X=\""+ReadData.x[37]+"\" Y=\""+ReadData.y[37]+"\" Z=\""+ReadData.z[37]+"\" A=\""+ReadData.a[37]+"\" B=\""+ReadData.b[37]+"\" C=\""+ReadData.c[37]+"\"/>"+ "\n"
                    +   "<xyzabc39 X=\""+ReadData.x[38]+"\" Y=\""+ReadData.y[38]+"\" Z=\""+ReadData.z[38]+"\" A=\""+ReadData.a[38]+"\" B=\""+ReadData.b[38]+"\" C=\""+ReadData.c[38]+"\"/>"+ "\n"
                    +   "<xyzabc40 X=\""+ReadData.x[39]+"\" Y=\""+ReadData.y[39]+"\" Z=\""+ReadData.z[39]+"\" A=\""+ReadData.a[39]+"\" B=\""+ReadData.b[39]+"\" C=\""+ReadData.c[39]+"\"/>"+ "\n"
                    +   "<xyzabc41 X=\""+ReadData.x[40]+"\" Y=\""+ReadData.y[40]+"\" Z=\""+ReadData.z[40]+"\" A=\""+ReadData.a[40]+"\" B=\""+ReadData.b[40]+"\" C=\""+ReadData.c[40]+"\"/>"+ "\n"
                    +   "<xyzabc42 X=\""+ReadData.x[41]+"\" Y=\""+ReadData.y[41]+"\" Z=\""+ReadData.z[41]+"\" A=\""+ReadData.a[41]+"\" B=\""+ReadData.b[41]+"\" C=\""+ReadData.c[41]+"\"/>"+ "\n"
                    +   "<xyzabc43 X=\""+ReadData.x[42]+"\" Y=\""+ReadData.y[42]+"\" Z=\""+ReadData.z[42]+"\" A=\""+ReadData.a[42]+"\" B=\""+ReadData.b[42]+"\" C=\""+ReadData.c[42]+"\"/>"+ "\n"
                    +   "<xyzabc44 X=\""+ReadData.x[43]+"\" Y=\""+ReadData.y[43]+"\" Z=\""+ReadData.z[43]+"\" A=\""+ReadData.a[43]+"\" B=\""+ReadData.b[43]+"\" C=\""+ReadData.c[43]+"\"/>"+ "\n"
                    +   "<xyzabc45 X=\""+ReadData.x[44]+"\" Y=\""+ReadData.y[44]+"\" Z=\""+ReadData.z[44]+"\" A=\""+ReadData.a[44]+"\" B=\""+ReadData.b[44]+"\" C=\""+ReadData.c[44]+"\"/>"+ "\n"
                    +   "<xyzabc46 X=\""+ReadData.x[45]+"\" Y=\""+ReadData.y[45]+"\" Z=\""+ReadData.z[45]+"\" A=\""+ReadData.a[45]+"\" B=\""+ReadData.b[45]+"\" C=\""+ReadData.c[45]+"\"/>"+ "\n"
                    +   "<xyzabc47 X=\""+ReadData.x[46]+"\" Y=\""+ReadData.y[46]+"\" Z=\""+ReadData.z[46]+"\" A=\""+ReadData.a[46]+"\" B=\""+ReadData.b[46]+"\" C=\""+ReadData.c[46]+"\"/>"+ "\n"
                    +   "<xyzabc48 X=\""+ReadData.x[47]+"\" Y=\""+ReadData.y[47]+"\" Z=\""+ReadData.z[47]+"\" A=\""+ReadData.a[47]+"\" B=\""+ReadData.b[47]+"\" C=\""+ReadData.c[47]+"\"/>"+ "\n"
                    +   "<xyzabc49 X=\""+ReadData.x[48]+"\" Y=\""+ReadData.y[48]+"\" Z=\""+ReadData.z[48]+"\" A=\""+ReadData.a[48]+"\" B=\""+ReadData.b[48]+"\" C=\""+ReadData.c[48]+"\"/>"+ "\n"
                    +   "<xyzabc50 X=\""+ReadData.x[49]+"\" Y=\""+ReadData.y[49]+"\" Z=\""+ReadData.z[49]+"\" A=\""+ReadData.a[49]+"\" B=\""+ReadData.b[49]+"\" C=\""+ReadData.c[49]+"\"/>"+ "\n"
                    +   "<xyzabc51 X=\""+ReadData.x[50]+"\" Y=\""+ReadData.y[50]+"\" Z=\""+ReadData.z[50]+"\" A=\""+ReadData.a[50]+"\" B=\""+ReadData.b[50]+"\" C=\""+ReadData.c[50]+"\"/>"+ "\n"
                    +   "<xyzabc52 X=\""+ReadData.x[51]+"\" Y=\""+ReadData.y[51]+"\" Z=\""+ReadData.z[51]+"\" A=\""+ReadData.a[51]+"\" B=\""+ReadData.b[51]+"\" C=\""+ReadData.c[51]+"\"/>"+ "\n"
                    +   "<xyzabc53 X=\""+ReadData.x[52]+"\" Y=\""+ReadData.y[52]+"\" Z=\""+ReadData.z[52]+"\" A=\""+ReadData.a[52]+"\" B=\""+ReadData.b[52]+"\" C=\""+ReadData.c[52]+"\"/>"+ "\n"
                    +   "<xyzabc54 X=\""+ReadData.x[53]+"\" Y=\""+ReadData.y[53]+"\" Z=\""+ReadData.z[53]+"\" A=\""+ReadData.a[53]+"\" B=\""+ReadData.b[53]+"\" C=\""+ReadData.c[53]+"\"/>"+ "\n"
                    +   "<xyzabc55 X=\""+ReadData.x[54]+"\" Y=\""+ReadData.y[54]+"\" Z=\""+ReadData.z[54]+"\" A=\""+ReadData.a[54]+"\" B=\""+ReadData.b[54]+"\" C=\""+ReadData.c[54]+"\"/>"+ "\n"
                    +   "<xyzabc56 X=\""+ReadData.x[55]+"\" Y=\""+ReadData.y[55]+"\" Z=\""+ReadData.z[55]+"\" A=\""+ReadData.a[55]+"\" B=\""+ReadData.b[55]+"\" C=\""+ReadData.c[55]+"\"/>"+ "\n"
                    +   "<xyzabc57 X=\""+ReadData.x[56]+"\" Y=\""+ReadData.y[56]+"\" Z=\""+ReadData.z[56]+"\" A=\""+ReadData.a[56]+"\" B=\""+ReadData.b[56]+"\" C=\""+ReadData.c[56]+"\"/>"+ "\n"
                    +   "<xyzabc58 X=\""+ReadData.x[57]+"\" Y=\""+ReadData.y[57]+"\" Z=\""+ReadData.z[57]+"\" A=\""+ReadData.a[57]+"\" B=\""+ReadData.b[57]+"\" C=\""+ReadData.c[57]+"\"/>"+ "\n"
                    +   "<xyzabc59 X=\""+ReadData.x[58]+"\" Y=\""+ReadData.y[58]+"\" Z=\""+ReadData.z[58]+"\" A=\""+ReadData.a[58]+"\" B=\""+ReadData.b[58]+"\" C=\""+ReadData.c[58]+"\"/>"+ "\n"
                    +   "<xyzabc60 X=\""+ReadData.x[59]+"\" Y=\""+ReadData.y[59]+"\" Z=\""+ReadData.z[59]+"\" A=\""+ReadData.a[59]+"\" B=\""+ReadData.b[59]+"\" C=\""+ReadData.c[59]+"\"/>"+ "\n"
                    +   "<xyzabc61 X=\""+ReadData.x[60]+"\" Y=\""+ReadData.y[60]+"\" Z=\""+ReadData.z[60]+"\" A=\""+ReadData.a[60]+"\" B=\""+ReadData.b[60]+"\" C=\""+ReadData.c[60]+"\"/>"+ "\n"
                    +   "<xyzabc62 X=\""+ReadData.x[61]+"\" Y=\""+ReadData.y[61]+"\" Z=\""+ReadData.z[61]+"\" A=\""+ReadData.a[61]+"\" B=\""+ReadData.b[61]+"\" C=\""+ReadData.c[61]+"\"/>"+ "\n"
                    +   "<xyzabc63 X=\""+ReadData.x[62]+"\" Y=\""+ReadData.y[62]+"\" Z=\""+ReadData.z[62]+"\" A=\""+ReadData.a[62]+"\" B=\""+ReadData.b[62]+"\" C=\""+ReadData.c[62]+"\"/>"+ "\n"
                    +   "<xyzabc64 X=\""+ReadData.x[63]+"\" Y=\""+ReadData.y[63]+"\" Z=\""+ReadData.z[63]+"\" A=\""+ReadData.a[63]+"\" B=\""+ReadData.b[63]+"\" C=\""+ReadData.c[63]+"\"/>"+ "\n"
                    +   "<xyzabc65 X=\""+ReadData.x[64]+"\" Y=\""+ReadData.y[64]+"\" Z=\""+ReadData.z[64]+"\" A=\""+ReadData.a[64]+"\" B=\""+ReadData.b[64]+"\" C=\""+ReadData.c[64]+"\"/>"+ "\n"
                    +   "<xyzabc66 X=\""+ReadData.x[65]+"\" Y=\""+ReadData.y[65]+"\" Z=\""+ReadData.z[65]+"\" A=\""+ReadData.a[65]+"\" B=\""+ReadData.b[65]+"\" C=\""+ReadData.c[65]+"\"/>"+ "\n"
                    +   "<xyzabc67 X=\""+ReadData.x[66]+"\" Y=\""+ReadData.y[66]+"\" Z=\""+ReadData.z[66]+"\" A=\""+ReadData.a[66]+"\" B=\""+ReadData.b[66]+"\" C=\""+ReadData.c[66]+"\"/>"+ "\n"
                    +   "<xyzabc68 X=\""+ReadData.x[67]+"\" Y=\""+ReadData.y[67]+"\" Z=\""+ReadData.z[67]+"\" A=\""+ReadData.a[67]+"\" B=\""+ReadData.b[67]+"\" C=\""+ReadData.c[67]+"\"/>"+ "\n"
                    +   "<xyzabc69 X=\""+ReadData.x[68]+"\" Y=\""+ReadData.y[68]+"\" Z=\""+ReadData.z[68]+"\" A=\""+ReadData.a[68]+"\" B=\""+ReadData.b[68]+"\" C=\""+ReadData.c[68]+"\"/>"+ "\n"
                    +   "<xyzabc70 X=\""+ReadData.x[69]+"\" Y=\""+ReadData.y[69]+"\" Z=\""+ReadData.z[69]+"\" A=\""+ReadData.a[69]+"\" B=\""+ReadData.b[69]+"\" C=\""+ReadData.c[69]+"\"/>"+ "\n"
                    +   "<xyzabc71 X=\""+ReadData.x[70]+"\" Y=\""+ReadData.y[70]+"\" Z=\""+ReadData.z[70]+"\" A=\""+ReadData.a[70]+"\" B=\""+ReadData.b[70]+"\" C=\""+ReadData.c[70]+"\"/>"+ "\n"
                    +   "<xyzabc72 X=\""+ReadData.x[71]+"\" Y=\""+ReadData.y[71]+"\" Z=\""+ReadData.z[71]+"\" A=\""+ReadData.a[71]+"\" B=\""+ReadData.b[71]+"\" C=\""+ReadData.c[71]+"\"/>"+ "\n"
                    +   "<xyzabc73 X=\""+ReadData.x[72]+"\" Y=\""+ReadData.y[72]+"\" Z=\""+ReadData.z[72]+"\" A=\""+ReadData.a[72]+"\" B=\""+ReadData.b[72]+"\" C=\""+ReadData.c[72]+"\"/>"+ "\n"
                    +   "<xyzabc74 X=\""+ReadData.x[73]+"\" Y=\""+ReadData.y[73]+"\" Z=\""+ReadData.z[73]+"\" A=\""+ReadData.a[73]+"\" B=\""+ReadData.b[73]+"\" C=\""+ReadData.c[73]+"\"/>"+ "\n"
                    +   "<xyzabc75 X=\""+ReadData.x[74]+"\" Y=\""+ReadData.y[74]+"\" Z=\""+ReadData.z[74]+"\" A=\""+ReadData.a[74]+"\" B=\""+ReadData.b[74]+"\" C=\""+ReadData.c[74]+"\"/>"+ "\n"
                    +   "<xyzabc76 X=\""+ReadData.x[75]+"\" Y=\""+ReadData.y[75]+"\" Z=\""+ReadData.z[75]+"\" A=\""+ReadData.a[75]+"\" B=\""+ReadData.b[75]+"\" C=\""+ReadData.c[75]+"\"/>"+ "\n"
                    +   "<xyzabc77 X=\""+ReadData.x[76]+"\" Y=\""+ReadData.y[76]+"\" Z=\""+ReadData.z[76]+"\" A=\""+ReadData.a[76]+"\" B=\""+ReadData.b[76]+"\" C=\""+ReadData.c[76]+"\"/>"+ "\n"
                    +   "<xyzabc78 X=\""+ReadData.x[77]+"\" Y=\""+ReadData.y[77]+"\" Z=\""+ReadData.z[77]+"\" A=\""+ReadData.a[77]+"\" B=\""+ReadData.b[77]+"\" C=\""+ReadData.c[77]+"\"/>"+ "\n"
                    +   "<xyzabc79 X=\""+ReadData.x[78]+"\" Y=\""+ReadData.y[78]+"\" Z=\""+ReadData.z[78]+"\" A=\""+ReadData.a[78]+"\" B=\""+ReadData.b[78]+"\" C=\""+ReadData.c[78]+"\"/>"+ "\n"
                    +   "<xyzabc80 X=\""+ReadData.x[79]+"\" Y=\""+ReadData.y[79]+"\" Z=\""+ReadData.z[79]+"\" A=\""+ReadData.a[79]+"\" B=\""+ReadData.b[79]+"\" C=\""+ReadData.c[79]+"\"/>"+ "\n"
                    +   "<xyzabc81 X=\""+ReadData.x[80]+"\" Y=\""+ReadData.y[80]+"\" Z=\""+ReadData.z[80]+"\" A=\""+ReadData.a[80]+"\" B=\""+ReadData.b[80]+"\" C=\""+ReadData.c[80]+"\"/>"+ "\n"
                    +   "<xyzabc82 X=\""+ReadData.x[81]+"\" Y=\""+ReadData.y[81]+"\" Z=\""+ReadData.z[81]+"\" A=\""+ReadData.a[81]+"\" B=\""+ReadData.b[81]+"\" C=\""+ReadData.c[81]+"\"/>"+ "\n"
                    +   "<xyzabc83 X=\""+ReadData.x[82]+"\" Y=\""+ReadData.y[82]+"\" Z=\""+ReadData.z[82]+"\" A=\""+ReadData.a[82]+"\" B=\""+ReadData.b[82]+"\" C=\""+ReadData.c[82]+"\"/>"+ "\n"
                    +   "<xyzabc84 X=\""+ReadData.x[83]+"\" Y=\""+ReadData.y[83]+"\" Z=\""+ReadData.z[83]+"\" A=\""+ReadData.a[83]+"\" B=\""+ReadData.b[83]+"\" C=\""+ReadData.c[83]+"\"/>"+ "\n"
                    +   "<xyzabc85 X=\""+ReadData.x[84]+"\" Y=\""+ReadData.y[84]+"\" Z=\""+ReadData.z[84]+"\" A=\""+ReadData.a[84]+"\" B=\""+ReadData.b[84]+"\" C=\""+ReadData.c[84]+"\"/>"+ "\n"
                    +   "<xyzabc86 X=\""+ReadData.x[85]+"\" Y=\""+ReadData.y[85]+"\" Z=\""+ReadData.z[85]+"\" A=\""+ReadData.a[85]+"\" B=\""+ReadData.b[85]+"\" C=\""+ReadData.c[85]+"\"/>"+ "\n"
                    +   "<xyzabc87 X=\""+ReadData.x[86]+"\" Y=\""+ReadData.y[86]+"\" Z=\""+ReadData.z[86]+"\" A=\""+ReadData.a[86]+"\" B=\""+ReadData.b[86]+"\" C=\""+ReadData.c[86]+"\"/>"+ "\n"
                    +   "<xyzabc88 X=\""+ReadData.x[87]+"\" Y=\""+ReadData.y[87]+"\" Z=\""+ReadData.z[87]+"\" A=\""+ReadData.a[87]+"\" B=\""+ReadData.b[87]+"\" C=\""+ReadData.c[87]+"\"/>"+ "\n"
                    +   "<xyzabc89 X=\""+ReadData.x[88]+"\" Y=\""+ReadData.y[88]+"\" Z=\""+ReadData.z[88]+"\" A=\""+ReadData.a[88]+"\" B=\""+ReadData.b[88]+"\" C=\""+ReadData.c[88]+"\"/>"+ "\n"
                    +   "<xyzabc90 X=\""+ReadData.x[89]+"\" Y=\""+ReadData.y[89]+"\" Z=\""+ReadData.z[89]+"\" A=\""+ReadData.a[89]+"\" B=\""+ReadData.b[89]+"\" C=\""+ReadData.c[89]+"\"/>"+ "\n"
                    +   "<xyzabc91 X=\""+ReadData.x[90]+"\" Y=\""+ReadData.y[90]+"\" Z=\""+ReadData.z[90]+"\" A=\""+ReadData.a[90]+"\" B=\""+ReadData.b[90]+"\" C=\""+ReadData.c[90]+"\"/>"+ "\n"
                    +   "<xyzabc92 X=\""+ReadData.x[91]+"\" Y=\""+ReadData.y[91]+"\" Z=\""+ReadData.z[91]+"\" A=\""+ReadData.a[91]+"\" B=\""+ReadData.b[91]+"\" C=\""+ReadData.c[91]+"\"/>"+ "\n"
                    +   "<xyzabc93 X=\""+ReadData.x[92]+"\" Y=\""+ReadData.y[92]+"\" Z=\""+ReadData.z[92]+"\" A=\""+ReadData.a[92]+"\" B=\""+ReadData.b[92]+"\" C=\""+ReadData.c[92]+"\"/>"+ "\n"
                    +   "<xyzabc94 X=\""+ReadData.x[93]+"\" Y=\""+ReadData.y[93]+"\" Z=\""+ReadData.z[93]+"\" A=\""+ReadData.a[93]+"\" B=\""+ReadData.b[93]+"\" C=\""+ReadData.c[93]+"\"/>"+ "\n"
                    +   "<xyzabc95 X=\""+ReadData.x[94]+"\" Y=\""+ReadData.y[94]+"\" Z=\""+ReadData.z[94]+"\" A=\""+ReadData.a[94]+"\" B=\""+ReadData.b[94]+"\" C=\""+ReadData.c[94]+"\"/>"+ "\n"
                    +   "<xyzabc96 X=\""+ReadData.x[95]+"\" Y=\""+ReadData.y[95]+"\" Z=\""+ReadData.z[95]+"\" A=\""+ReadData.a[95]+"\" B=\""+ReadData.b[95]+"\" C=\""+ReadData.c[95]+"\"/>"+ "\n"
                    +   "<xyzabc97 X=\""+ReadData.x[96]+"\" Y=\""+ReadData.y[96]+"\" Z=\""+ReadData.z[96]+"\" A=\""+ReadData.a[96]+"\" B=\""+ReadData.b[96]+"\" C=\""+ReadData.c[96]+"\"/>"+ "\n"
                    +   "<xyzabc98 X=\""+ReadData.x[97]+"\" Y=\""+ReadData.y[97]+"\" Z=\""+ReadData.z[97]+"\" A=\""+ReadData.a[97]+"\" B=\""+ReadData.b[97]+"\" C=\""+ReadData.c[97]+"\"/>"+ "\n"
                    +   "<xyzabc99 X=\""+ReadData.x[98]+"\" Y=\""+ReadData.y[98]+"\" Z=\""+ReadData.z[98]+"\" A=\""+ReadData.a[98]+"\" B=\""+ReadData.b[98]+"\" C=\""+ReadData.c[98]+"\"/>"+ "\n"
                    +   "<xyzabc100 X=\""+ReadData.x[99]+"\" Y=\""+ReadData.y[99]+"\" Z=\""+ReadData.z[99]+"\" A=\""+ReadData.a[99]+"\" B=\""+ReadData.b[99]+"\" C=\""+ReadData.c[99]+"\"/>"+ "\n"
                    +   "</Read>"+ "\n"
                    +   "<Show error=\""+isContinue+"\" temp=\"9929\">Taginfo in attributes</Show>"+ "\n" 
                    +   "<Free>2912</Free>" + "\n" 
                    +   "</Sensor>";
            // 发送XML字符串
            PrintWriter out = new PrintWriter(mySocket.getOutputStream(), true);
            out.println(xmlString);
            out.flush();

            // ------------ XML接收資料 (DOM)------------
            InputStream is = mySocket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String brString = br.readLine();
            System.out.println(brString);

            // 將STRING轉成NODE物件
            // 得到DocumentBuilderFactory的實體
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            // 得到DocumentBuilder的實體
            DocumentBuilder db = dbf.newDocumentBuilder();
            // 得到Document的實體
            org.w3c.dom.Document document = db.parse(new ByteArrayInputStream(brString.getBytes()));
            // 得到Element的實體, 此物件是實際的XML內容
            Element el = document.getDocumentElement();
            // 得到節點的資料
            NodeList nl = el.getElementsByTagName("LastPos");

            int nlInt = nl.getLength();
            System.out.println(nlInt);
            // X的值為LastPos的屬性所以要先getAttributes()
            String xPosString = nl.item(0).getAttributes().getNamedItem("X").getNodeValue();
            String yPosString = nl.item(0).getAttributes().getNamedItem("Y").getNodeValue();
            System.out.println("X=" + xPosString + " Y=" + yPosString);

        } catch (IOException | ParserConfigurationException | SAXException | TransformerFactoryConfigurationError e) {
            // TODO Auto-generated catch block
            wftolog.addLog("ERROR:傳輸PTP資料失敗。\n");
            e.printStackTrace();
        } finally {

            try {
                mySocket.close();
                myServer.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                wftolog.addLog("ERROR:傳輸PTP資料成功, 關閉通道失敗。\n");
                e.printStackTrace();
            }

        }

    }
}

程序会在调用readBufferPTP()方法时停止。在方法中,代码不能在运行里面的try catch和运行 finally直接:

if (ReadFile.isPTP == 0) {
                System.out.println("進去讀LIN資料串");
                **readBufferLIN();**
                wftolog.addLog("傳輸LIN資料成功。");
            } else {
                //確認是否是最後一個檔案
                if (ReadFile.fileCounter == (idv.xml.serverclient.ReadData.fileNumber)) {
                    isContinue = "1";
                }
                System.out.println("進去讀PTP資料串");
                readBufferPTP();
                wftolog.addLog("傳輸PTP資料成功。");
                System.out.println("readFile.fileCounter="+(ReadFile.fileCounter-1)+";readData.fileNumber="+(idv.xml.serverclient.ReadData.fileNumber - 1));
                if (ReadFile.fileCounter == (idv.xml.serverclient.ReadData.fileNumber)) {
                    break;
                }
            }

由于没有错误消息,我没有任何照片给你。我将上传 jar 文件。

因为不知道怎么上传文件,所以把Manifest文件past如下:

Manifest-Version: 1.0
Main-Class: idv.xml.serverclient.HMI_Window
Class-Path: lib/jaxen-1.1.6.jar lib/jdom-2.0.6.jar lib/jdom-2.0.6-contrib.jar
  lib/jdom-2.0.6-javadoc.jar lib/jdom-2.0.6-junit.jar lib/jdom-2.0.6-sources.jar 
  lib/xerceslmpl.jar lib/xml-apis.jar lib/xalan/serializer-2.7.2.jar 
  lib/xalan/xalan-2.7.2.jar

听起来你的项目中包含了 eclipse 在构建它时已经包含的库,因此它可以 运行 jar 文件,但是当你尝试 运行 它在资源管理器中时,那些库不再包含文件。

如果您将所有库文件和原始 jar 文件压缩到一个 Zip 文件中,然后将其转换回 jar 文件,您的程序应该可以从文件资源管理器中执行。

您可以通过提取 jar 库文件中的所有内容并将所有内容添加到一个压缩文件中来执行此操作,唯一的清单文件应该来自您的主 jar 文件。

如果您不确定如何执行此操作,

This Link 应该会为您提供更多详细信息。确保相应地编辑清单文件。

我已经解决了问题。 因为我知道我的代码是没有问题的。问题一定是 jar 导出。所以我尝试了从 Eclipse 中导出源代码的各种方法。我做的最后一种方法是 export > Runnable JAR File > Extract required libraries into generated JAR。 感谢您的帮助。