無法從 shell 腳本執行 java 應用程式

無法從 shell 腳本執行 java 應用程式

下載並解壓縮zip套件後,我將modelsphere.bat檔案複製到modelsphere.sh,並將內容變更為:

 java -ms64m -mx512m -ss16m -classpath "./modelsphere.jar:./resources.zip:./resources:./targets:./lib/jakarta-regexp-1.5/jakarta-regexp-1.5.jar:./lib/velocity-1.6.1/velocity-1.6.1.jar:./lib/jazzy-core/jazzy-core.jar:./lib/jython-2.2.1/jython.jar:./lib/velocity-1.6.1/lib/commons-collections-3.2.1.jar:./lib/velocity-1.6.1/lib/commons-lang-2.4.jar:./lib/lablib-checkboxtree-3.0.2.jar" org.modelsphere.sms.Application

但是當使用指令“./modelsphere.sh”執行 modelsphere.sh 時,會引發以下例外:

 Exception in thread "main" java.lang.NoClassDefFoundError: org/modelsphere/sms/Application
Caused by: java.lang.ClassNotFoundException: org.modelsphere.sms.Application
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
.  Program will exit.in class: org.modelsphere.sms.Application

當我運行命令時,

java -ms64m -mx512m -ss16m -classpath "./modelsphere.jar:./resources.zip:./resources:./targets:./lib/jakarta-regexp-1.5/jakarta-regexp-1.5.jar:./lib/velocity-1.6.1/velocity-1.6.1.jar:./lib/jazzy-core/jazzy-core.jar:./lib/jython-2.2.1/jython.jar:./lib/velocity-1.6.1/lib/commons-collections-3.2.1.jar:./lib/velocity-1.6.1/lib/commons-lang-2.4.jar:./lib/lablib-checkboxtree-3.0.2.jar" org.modelsphere.sms.Application

這是“modelsphere.sh”檔案的內容,它可以工作。

為什麼?如何使用「modelsphere.sh」的 shell 檔案啟動 Open ModelSphere?

有人能給我任何意見嗎?提前致謝。

答案1

它可能有 DOS 行結尾(\r\n 而不是 \n)。看http://mywiki.wooledge.org/BashFAQ/052

為了獲得良好的實踐,您應該確保文件的第一行顯示#!/bin/sh

相關內容