マイクロソフト社の陰謀ですね。ちょっとした関税外障壁があるわけです。
まず、そのままjavacでコンパイルしてもclassファイルができるだけです。ライブラリを組み込んで動いても、とっても不便なディレクトリ構造は動かせない。
ここは jar ファイルの作り方を工夫すれば動きます。プロジェクトを右クリック、Export からダイアログで Runnable JAR file を選択します。
或いはライブラリを組み込んでマニフェストファイルを設定し Main-Class を設定します。これだってかなりな手間ですが、話はこれで終わらない。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<target name="jar" depends="build"> | |
<jar jarfile="SCDF_Generator.jar" basedir="bin"> | |
<manifest> | |
<attribute name="Main-Class" value="DirList" /> | |
</manifest> | |
<zipgroupfileset dir="lib" includes="*.jar" /> | |
</jar> | |
</target> |
出来上がった jar 実行ファイルがエラーも出さず動いたと思えば動かしているのはjavawでjavaです。つまりコンソールアプリは動かない。出力はまったくなしです。
どうしてもコマンド一つで動く jar 実行ファイルを作りたい場合。copy コマンドでバッチファイルをコピーする裏技があります。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
java -jar "%~f0" %* | |
exit /b %ERRORLEVEL% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy /b src.jar+DirList.ar DirList.bat |