質問するログイン新規登録
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

1回答

5282閲覧

jarを開く時のエラーについて

boru1049

総合スコア2

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2020/11/20 05:21

編集2020/11/24 00:19

0

0

SVcodeでjarを作成して、コマンドプロンプトで開こうとしたら

エラー: メイン・クラスhenkan.Appを初期化できません
原因: java.lang.NoClassDefFoundError: org/apache/poi/EncryptedDocumentException

と出てきて、詳しく調べたところXSSFWorkbookでのところでひっかかってるみたいで、恐らくpom.xmlでの設定が問題だと思うのですが解決方法が見つからないです

pom.xml

1<?xml version="1.0" encoding="UTF-8"?> 2 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>henkan</groupId> 8 <artifactId>te</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 11 <name>te</name> 12 <!-- FIXME change it to the project's website --> 13 <url>http://www.example.com</url> 14 15 <properties> 16 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 17 <maven.compiler.source>15</maven.compiler.source> 18 <maven.compiler.target>15</maven.compiler.target> 19 </properties> 20 21 <dependencies> 22 <dependency> 23 <groupId>junit</groupId> 24 <artifactId>junit</artifactId> 25 <version>4.11</version> 26 <scope>test</scope> 27 </dependency> 28 <dependency> 29 <groupId>org.apache.poi</groupId> 30 <artifactId>poi</artifactId> 31 <version>4.1.2</version> 32 </dependency> 33 <dependency> 34 <groupId>org.apache.poi</groupId> 35 <artifactId>poi-ooxml</artifactId> 36 <version>4.1.2</version> 37 </dependency> 38 </dependencies> 39 40 <build> 41 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 42 <plugins> 43 <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> 44 <plugin> 45 <artifactId>maven-clean-plugin</artifactId> 46 <version>3.1.0</version> 47 </plugin> 48 <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> 49 <plugin> 50 <artifactId>maven-resources-plugin</artifactId> 51 <version>3.0.2</version> 52 </plugin> 53 <plugin> 54 <artifactId>maven-compiler-plugin</artifactId> 55 <version>3.8.0</version> 56 </plugin> 57 <plugin> 58 <artifactId>maven-surefire-plugin</artifactId> 59 <version>2.22.1</version> 60 </plugin> 61 <plugin> 62 <artifactId>maven-jar-plugin</artifactId> 63 <version>3.0.2</version> 64 </plugin> 65 <plugin> 66 <artifactId>maven-install-plugin</artifactId> 67 <version>2.5.2</version> 68 </plugin> 69 <plugin> 70 <artifactId>maven-deploy-plugin</artifactId> 71 <version>2.8.2</version> 72 </plugin> 73 <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> 74 <plugin> 75 <artifactId>maven-site-plugin</artifactId> 76 <version>3.7.1</version> 77 </plugin> 78 <plugin> 79 <artifactId>maven-project-info-reports-plugin</artifactId> 80 <version>3.0.0</version> 81 </plugin> 82 <plugin> 83 <groupId>org.apache.maven.plugins</groupId> 84 <artifactId>maven-jar-plugin</artifactId> 85 <configuration> 86 <archive> 87 <manifest> 88 <mainClass>henkan.App</mainClass> 89 <addClasspath>true</addClasspath> 90 <addExtensions>true</addExtensions> 91 </manifest> 92 </archive> 93 </configuration> 94 </plugin> 95 </plugins> 96 </pluginManagement> 97 </build> 98</project>

プラグインの追加をすればいいと思うのですが、どうすればよいでしょうか

追記
作成した時の手順は mvn package で作成しました(この時にエラーなどの警告は無し)
開く方法としてはコマンドプロンプトで java -jar で開こうとして上記の様なエラー内容です。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

SVcodeでjarを作成して、

作成したときの操作手順を教えてください。

コマンドプロンプトで開こうとしたら

コマンドプロンプトに、どんなコマンドを打ちましたか?

jarファイルを解凍する方法を知ってますか?
もし知ってるなら、適当なフォルダに解凍して、その中に含まれるMANIFEST.MFというファイルの内容を教えてください。

2020-11-24追記

java -jar hoge.jarで実行するためには、hoge.jarの中に、henkan.Appだけでなく、すべての依存ライブラリのクラスファイルが含まれている必要があります(いわゆるexecutable jar)。
おそらく、mvn packageで作ったjarファイルには、henkan.Appのクラスファイルだけが入ってるのではないでしょうか(jar tvf hoge.jarすればわかりますよね)。その場合、実行時には、依存ライブラリへのクラスパスを指定する必要があります。

以下の方法でexecutable jarを作れると思うので、お試しください(これがオーソドックスな方法かどうかは分かりませんが)。

(1)pom.xmlに以下のプラグインを追加

xml

1<plugin> 2 <groupId>org.apache.maven.plugins</groupId> 3 <artifactId>maven-assembly-plugin</artifactId> 4 <version>2.3</version> 5 <configuration> 6 <archive> 7 <manifest> 8 <mainClass> 9 henkan.App 10 </mainClass> 11 </manifest> 12 </archive> 13 <descriptorRefs> 14 <descriptorRef>with-dependencies</descriptorRef> 15 </descriptorRefs> 16 </configuration> 17 <executions> 18 <execution> 19 <phase>package</phase> 20 <goals> 21 <goal>single</goal> 22 </goals> 23 </execution> 24 </executions> 25</plugin>

(2)ターミナルで以下のコマンドを実行

$ mvn clean compile assembly:single

これで、targetディレクトリの下にxxxxx-with-dependencies.jarができると思います。

(3)実行する

$ java -jar target/xxxxx-with-dependencies.jar

投稿2020/11/20 14:43

編集2020/11/24 12:16
gpsoft

総合スコア1323

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

gpsoft

2020/11/21 07:44

こういう内容は、「追記・修正依頼」に書くべきだったようですね。 失礼しました。
boru1049

2020/11/24 00:21

返信遅れてすみません、追記しました
boru1049

2020/11/24 01:08

MANIFEST.MFについては以下のような状態です Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.6.3 Built-By: Build-Jdk: 15.0.1 Class-Path: poi-4.1.2.jar commons-codec-1.13.jar commons-collections4-4. 4.jar commons-math3-3.6.1.jar SparseBitSet-1.2.jar poi-ooxml-4.1.2.jar poi-ooxml-schemas-4.1.2.jar xmlbeans-3.1.0.jar commons-compress-1.19.ja r curvesapi-1.06.jar Main-Class: henkan.App Extension-List: poi commons-codec commons-collections4 commons-math3 Spa rseBitSet poi-ooxml poi-ooxml-schemas xmlbeans commons-compress curvesa pi poi-Extension-Name: poi poi-Implementation-Version: 4.1.2 commons-codec-Extension-Name: commons-codec commons-codec-Implementation-Version: 1.13 commons-collections4-Extension-Name: commons-collections4 commons-collections4-Implementation-Version: 4.4 commons-math3-Extension-Name: commons-math3 commons-math3-Implementation-Version: 3.6.1 SparseBitSet-Extension-Name: SparseBitSet SparseBitSet-Implementation-Version: 1.2 poi-ooxml-Extension-Name: poi-ooxml poi-ooxml-Implementation-Version: 4.1.2 poi-ooxml-schemas-Extension-Name: poi-ooxml-schemas poi-ooxml-schemas-Implementation-Version: 4.1.2 xmlbeans-Extension-Name: xmlbeans xmlbeans-Implementation-Version: 3.1.0 commons-compress-Extension-Name: commons-compress commons-compress-Implementation-Version: 1.19 curvesapi-Extension-Name: curvesapi curvesapi-Implementation-Version: 1.06 Built-Byは名前なので意図的に抜いてます
gpsoft

2020/11/24 12:18

依存ライブラリがjarに含まれてないのが原因じゃないかと予想してるのですが、自信は無いです。ひとまず、回答欄を編集しておきました。参考にしてください。
boru1049

2020/11/26 05:02

with-dependenciesの所がこのままだとエラーで作れなかったのですがjar-with-dependenciesと書き換えればコマンドプロンプトで動かすことができました すごく助かりましたありがとうございます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問