![シェル スクリプトから Java アプリケーションを実行できません](https://rvso.com/image/1035909/%E3%82%B7%E3%82%A7%E3%83%AB%20%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%81%8B%E3%82%89%20Java%20%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93.png)
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」を使用して Open ModelSphere を起動するにはどうすればよいですか?
どなたか何かアドバイスをいただけませんか?よろしくお願いします。
答え1
おそらくDOSの行末(\nではなく\r\n)です。http://mywiki.wooledge.org/BashFAQ/052
良い練習として、ファイルの最初の行に次のように書いておくと良いでしょう。#!/bin/sh