Antを使って実行可能Jarをビルドする(EclipseのJava Compilerを使って)

Githubからzipをクローンして、解凍して、そのフォルダにターミナルで移動した。

antコマンドのあとに

Compile Initialize MakeJar Run

という選択肢がでている。書いたbuild.xmlファイルを読み込んでいるからだと思う。

まずMakeJarだと、Initializeを含んでいなくてだめ。

masa@em-p:~/Downloads/jaydle-project-clean_antbuild$ ant MakeJar 
Buildfile: /home/masa/Downloads/jaydle-project-clean_antbuild/build.xml

MakeJar:

BUILD FAILED
/home/masa/Downloads/jaydle-project-clean_antbuild/build.xml:49: /home/masa/Downloads/jaydle-project-clean_antbuild/bin does not exist.

Total time: 0 seconds

Initializeはうまくいった。でもCompileはうまくいかなかった。

Buildfile: /home/masa/Downloads/jaydle-project-clean_antbuild/build.xml

Initialize:
   [delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/bin
   [delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/jar
    [mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/bin
    [mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/jar

Compile:
    [javac] Since compiler setting isn't classic or modern, ignoring fork setting.

BUILD FAILED
/home/masa/Downloads/jaydle-project-clean_antbuild/build.xml:43: Class not found: org.eclipse.jdt.core.JDTCompilerAdapter

Total time: 0 seconds

というエラーがでた。Eclipseでも同様のエラーが出たが、Antの外部ツール設定でワークスペースと同じJREを使うようにしたら解決した。

今度はどうすればいいのだろう。

 

Eclipseで確認すると、一回目はビルドできるけど、二回目にエラーが出る

Ant build /home/masa/Public/git/jaydle-project/build.xml already in progress. Concurrent Ant builds are possible if you specify to build in a separate JRE.

昨日はできてなかったけな。てか、ハマってたエラー、スタックオーバーフローで質問していて、自分で解答していた。完全に忘れてた。はは。

あとターゲットの”Main Build”がターミナルで選べないのはなんでなんだろう。

 

Eclipseの話に戻ると、これはEclipse再起動で直った。でもMain Buildをするとまた再発。

なんかビルドが終わっていないらしい。

参考(英語)

https://groups.google.com/forum/#!topic/codenameone-discussions/ySxwDy4WzHo

 

実行をすると、Antが終了しないようだ。

話はもどって、

buiild.xmlを見ていると、compileのとこに

<ecj />

でecjの宣言を参照させていなかった。

この一行を追加で

<target name="Compile" depends="Initialize">
<javac 
classpathref="classpath" 
srcdir="${src}" 
destdir="${bin}" 
compiler="org.eclipse.jdt.core.JDTCompilerAdapter"

includeantruntime="false"
source="1.8"
target="1.8"
fork="true" 
debug="true" 
>
<ecj />
<compilerarg value="-Xdiags:verbose"/>
</javac>
</target>
masa@em-p:~/Downloads/jaydle-project-clean_antbuild$ ant Compile 
Buildfile: /home/masa/Downloads/jaydle-project-clean_antbuild/build.xml

Initialize:
   [delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/bin
   [delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/jar
    [mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/bin
    [mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/jar

Compile:
    [javac] Since compiler setting isn't classic or modern, ignoring fork setting.
    [javac] Since compiler setting isn't classic or modern, ignoring fork setting.
    [javac] Compiling 6 source files to /home/masa/Downloads/jaydle-project-clean_antbuild/bin
    [javac] Since compiler setting isn't classic or modern, ignoring fork setting.
    [javac] org.eclipse.jdt.internal.compiler.problem.AbortCompilation: 
    [javac] 	at org.eclipse.jdt.internal.compiler.batch.Main.initializeAnnotationProcessorManager(Main.java:4559)
    [javac] 	at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4669)
    [javac] 	at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1773)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.eclipse.jdt.core.JDTCompilerAdapter.execute(JDTCompilerAdapter.java:80)
    [javac] 	at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1160)
    [javac] 	at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:936)
    [javac] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac] 	at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac] 	at org.apache.tools.ant.Target.execute(Target.java:435)
    [javac] 	at org.apache.tools.ant.Target.performTasks(Target.java:456)
    [javac] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    [javac] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    [javac] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [javac] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    [javac] 	at org.apache.tools.ant.Main.runBuild(Main.java:853)
    [javac] 	at org.apache.tools.ant.Main.startAnt(Main.java:235)
    [javac] 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
    [javac] 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
    [javac] Unable to load annotation processing manager org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager from classpath.
    [javac] 

BUILD FAILED
/home/masa/Downloads/jaydle-project-clean_antbuild/build.xml:43: Compile failed; see the compiler error output for details.

Total time: 1 second

と、ClassFileNotFoundエラーは超えられたみたい。でもまだエラー出てる。

Unable to load annotation processing manager org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager from classpath.

aptパッケージ自体が、org.eclipse.jdt.core_3.13.102.v20180330-0919.jarに入っていないよう。

今回の設定だと、スルーしてくれずビルドフェイルになっているよう。

参考

https://bugs.eclipse.org/bugs/show_bug.cgi?id=478427

EclipseからJarコピーアンドペーストして使っていたけど、aptパッケージがないので、ecj.jarを使おう。

https://mvnrepository.com/artifact/org.eclipse.jdt.core.compiler/ecj/4.6.1

このjarにはaptパッケージがあった。

とりあえず、ecj.jarをant-libにコピーしたら

masa@em-p:~/Downloads/jaydle-project-clean_antbuild$ ant Compile 
Buildfile: /home/masa/Downloads/jaydle-project-clean_antbuild/build.xml

Initialize:
[delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/bin
[delete] Deleting directory /home/masa/Downloads/jaydle-project-clean_antbuild/jar
[mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/bin
[mkdir] Created dir: /home/masa/Downloads/jaydle-project-clean_antbuild/jar

Compile:
[javac] Since compiler setting isn't classic or modern, ignoring fork setting.
[javac] Since compiler setting isn't classic or modern, ignoring fork setting.
[javac] Compiling 6 source files to /home/masa/Downloads/jaydle-project-clean_antbuild/bin
[javac] Since compiler setting isn't classic or modern, ignoring fork setting.
[javac] ----------
[javac] 1. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 3)
[javac] import java.util.ArrayList;
[javac] ^^^^^^^^^^^^^^^^^^^
[javac] The import java.util.ArrayList is never used
[javac] ----------
[javac] 2. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 5)
[javac] import java.util.List;
[javac] ^^^^^^^^^^^^^^
[javac] The import java.util.List is never used
[javac] ----------
[javac] 3. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 22)
[javac] import static jaydle.BackgroundTask.*;
[javac] ^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.BackgroundTask is never used
[javac] ----------
[javac] 4. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 25)
[javac] public class Id3Tagger extends JFrame
[javac] ^^^^^^^^^
[javac] The serializable class Id3Tagger does not declare a static final serialVersionUID field of type long
[javac] ----------
[javac] 5. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 32)
[javac] private boolean DEBUG = true; 
[javac] ^^^^^
[javac] The value of the field Id3Tagger.DEBUG is not used
[javac] ----------
[javac] 6. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Id3Tagger.java (at line 49)
[javac] Matcher matcher=pattern.matcher(TargetText);
[javac] ^^^^^^^
[javac] The value of the local variable matcher is not used
[javac] ----------
[javac] ----------
[javac] 7. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 7)
[javac] import java.util.ArrayList;
[javac] ^^^^^^^^^^^^^^^^^^^
[javac] The import java.util.ArrayList is never used
[javac] ----------
[javac] 8. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 8)
[javac] import java.util.Arrays;
[javac] ^^^^^^^^^^^^^^^^
[javac] The import java.util.Arrays is never used
[javac] ----------
[javac] 9. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 10)
[javac] import java.util.regex.Matcher;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import java.util.regex.Matcher is never used
[javac] ----------
[javac] 10. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 11)
[javac] import java.util.regex.Pattern;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import java.util.regex.Pattern is never used
[javac] ----------
[javac] 11. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 14)
[javac] import com.mpatric.mp3agic.ID3v2;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import com.mpatric.mp3agic.ID3v2 is never used
[javac] ----------
[javac] 12. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 15)
[javac] import com.mpatric.mp3agic.Mp3File;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import com.mpatric.mp3agic.Mp3File is never used
[javac] ----------
[javac] 13. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 17)
[javac] import jaydle.JaydlePrototype.ButtonListener;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.JaydlePrototype.ButtonListener is never used
[javac] ----------
[javac] 14. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 21)
[javac] import static jaydle.BackgroundTask.*;
[javac] ^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.BackgroundTask is never used
[javac] ----------
[javac] 15. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydleMusicManager.java (at line 47)
[javac] private boolean DEBUG = true; 
[javac] ^^^^^
[javac] The value of the field JaydleMusicManager.DEBUG is not used
[javac] ----------
[javac] ----------
[javac] 16. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydlePrototype.java (at line 31)
[javac] public class JaydlePrototype extends JFrame 
[javac] ^^^^^^^^^^^^^^^
[javac] The serializable class JaydlePrototype does not declare a static final serialVersionUID field of type long
[javac] ----------
[javac] 17. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/JaydlePrototype.java (at line 119)
[javac] public static class saveDirClass implements Serializable // Named as serObj instance 
[javac] ^^^^^^^^^^^^
[javac] The serializable class saveDirClass does not declare a static final serialVersionUID field of type long
[javac] ----------
[javac] ----------
[javac] 18. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Main.java (at line 4)
[javac] import static jaydle.JaydlePrototype.*;
[javac] ^^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.JaydlePrototype is never used
[javac] ----------
[javac] 19. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Main.java (at line 5)
[javac] import static jaydle.BackgroundTask.*;
[javac] ^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.BackgroundTask is never used
[javac] ----------
[javac] ----------
[javac] 20. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Utilities.java (at line 2)
[javac] import static jaydle.Utilities.println;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.Utilities.println is never used
[javac] ----------
[javac] 21. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Utilities.java (at line 3)
[javac] import static jaydle.Utilities.regexFilterFileArray;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.Utilities.regexFilterFileArray is never used
[javac] ----------
[javac] 22. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Utilities.java (at line 4)
[javac] import static jaydle.Utilities.regexFilterList;
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] The import jaydle.Utilities.regexFilterList is never used
[javac] ----------
[javac] 23. WARNING in /home/masa/Downloads/jaydle-project-clean_antbuild/src/jaydle/Utilities.java (at line 134)
[javac] ObjectInputStream ois = new ObjectInputStream(fis);
[javac] ^^^
[javac] Resource leak: 'ois' is never closed
[javac] ----------
[javac] 23 problems (23 warnings)

BUILD SUCCESSFUL
Total time: 1 second

成功した!

ちなみに、Eclipseのjarコピーしていた時は、jdtCompilerAdapter.jarをjarからコピーして、ant-lib直下に置いていたけど、ecj.jarを使えば、ecj.jarだけで通るみたい。

コンパイルとJarの作成はうまくいったけど、JMMで実行時エラーでてるな。実行時じゃなくてClassNotFoundExceptionだな。

 [java] Exception in thread "main" java.lang.NoClassDefFoundError: com/mpatric/mp3agic/Mp3File
[java] at jaydle.Utilities.makeMp3TagTable3Rows(Utilities.java:287)
[java] at jaydle.JaydleMusicManager.initTable(JaydleMusicManager.java:73)
[java] at jaydle.JaydleMusicManager.main(JaydleMusicManager.java:171)
[java] Caused by: java.lang.ClassNotFoundException: com.mpatric.mp3agic.Mp3File
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 3 more

 

2 thoughts on “Antを使って実行可能Jarをビルドする(EclipseのJava Compilerを使って)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s