我正在尝试在我的 Linux 服务器上运行一个 jar 文件。在我的 Windows 桌面上,我可以使用以下命令很好地执行 jar 文件:
java -Xss1000m -XX:-UseGCOverheadLimit -Xmx5048m -jar test.jar
但是,当我在我的 Linux 服务器上运行它时,我收到以下错误:
java.io.StreamCorruptedException: invalid type code: 9D
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1374)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at com.test.test.Main.main(Main.java:41)
我的代码是:
public class Main {
public static void main(String[] args) throws Exception {
String fromTextFile = "";
String path = "";
if (!SystemUtils.IS_OS_WINDOWS)
path = "/var/www/tomcat/fetch/";
fromTextFile = path + "resources/ac_geonames_country_all.txt";
AhoCorasick tree = new AhoCorasick();
ObjectInputStream ois;
try {
ois = new ObjectInputStream(new FileInputStream(fromTextFile));
tree = (AhoCorasick) ois.readObject();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}