KDP(電子出版)のメモ 急急如律令

Amazon Kindleダイレクト・パブリッシングでの電子出版や電子書籍の作成販売について、文章やイラストの作成や編集方法について書いています。

EclipseからIntelliJ IDEAへ移行

 EclipseからIntelliJ IDEAへ移行しようと思ったんだが、実行できないので調べている。ビルドにAntを使っていたので今風のGradleにしたほうがいいのだろうか。使っているライブラリを最新のにしようとしたが動作チェックでいろいろあるので、まり進んでいない。Pleiades All in Oneを使っていたが日本語化しなくてもいいかなと感じたのでそのまま英語で使っている。

www.jetbrains.com

IntelliJ IDEAでAntを読み込んで実行したらビルド自体はできたのだけど、アプリケーションの実行ができない。原因を調べていると、ライブラリが読み込まれていないような感じがして、ライブラリの読み込み方を調べた。

 

pleiades.io

書いている通りにグローバルライブラリの定義とかをしてみたが、

「ライブラリをモジュールの依存関係に追加する」のところで追加したライブラリが見つからない。なのでbuild.gradleを手書きしてみた。

 

plugins {
    id 'java'
    id 'application'
}

mainClassName = 'AozoraEpub3'

repositories {
    mavenCentral()
}
sourceSets {
    main {
        java {
            srcDirs = ['src']
        } 

      resources {
            srcDirs= ["src"]
        }
    }
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.velocity/velocity
    implementation group: 'org.apache.velocity', name: 'velocity', version: '1.7'
    // https://mvnrepository.com/artifact/com.github.junrar/junrar
    implementation group: 'com.github.junrar', name: 'junrar', version: '7.5.4'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
    implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.4'
// https://mvnrepository.com/artifact/commons-lang/commons-lang
    implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
// https://mvnrepository.com/artifact/org.apache.commons/commons-compress
    implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.22'
// https://mvnrepository.com/artifact/commons-collections/commons-collections
    implementation group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
// https://mvnrepository.com/artifact/commons-cli/commons-cli
    implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
// https://mvnrepository.com/artifact/com.github.albfernandez/juniversalchardet
    implementation group: 'com.github.albfernandez', name: 'juniversalchardet', version: '2.4.0'

}

これでコマンドラインのほうは動くようになったが、アプリケーションのほうがいまいち動かない。

 

> Task :AozoraEpub3Applet.main() FAILED
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null
    at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:234)
    at AozoraEpub3Applet.init(AozoraEpub3Applet.java:472)
    at AozoraEpub3Applet.main(AozoraEpub3Applet.java:4720)

エラーメッセージを読んだ感じでは、画像の読み込み先にファイルが見つからないという感じか。eclipseやJARを作ったら見つかるのでclassファイルの状態で画像ファイルが見つからないのかな。

 その後、gradleにリソースのディレクトリを指定することでアプリが動いた。

qiita.com

stackoverflow.com

 

github.com

 

mergedoc.osdn.jp