2

私は Java コンソール アプリケーションを持っていますが、これまでは Netbeans IDE で開発されていました。Netbeans がアプリケーションをdistビルドすると、ディレクトリが作成され、アプリがこのディレクトリに jar アーカイブとしてビルドされ、dist/libすべての依存関係がコピーされます。このディレクトリを最終的な宛先にコピーして実行できます。

今、このプロジェクトを Maven に転送しようとしています。すべてがうまくいき、アプリをコンパイルしてパッケージ化でき、jar がtargetディレクトリに作成されます。maven-jar-pluginマニフェストにメイン クラスを設定し、maven-shade-pluginすべてのソースを 1 つの jar ファイルにパッケージ化するために使用します。

このようなMavenプロジェクトは、現実の世界でどのように展開されていますか? すべてのtargetディレクトリを使用し、それを最終的な宛先にコピーして、Netbeans で慣れているように実行する必要がありますか? 使用しない場合の結果はどうなりmaven-shade-pluginますか?依存関係として定義されているすべてのライブラリはどこにありますか? target私のテストプロジェクトでは、これらのライブラリがディレクトリに存在しないため、私は尋ねています。

私の質問 - Maven (なしmaven-shade-plugin) を介してパッケージ化された Java コンソール アプリケーション "A" と、このアプリケーションを実行する Linux サーバー "S" があります。すべてのターゲットディレクトリを手動でサーバー「S」にコピーできますか、またはこれを実際に解決するためのより良い/より自動化された方法はありますか?

4

2 に答える 2

6

Simply copying over the target directory will not solve your problem. I have packaged many standalone applications using Maven and I have used Maven Assembly Plugin for it. You can create a distribution archive (zip, tar.gz) using the assembly plugin which your customer can unzip and start running.

It depends on you, how you want your target application directory structure (release). I usually end up with something like

bin/
conf/
lib/
log/

The bin directory contains a shell / batch script to run your program by calling your main class, setting appropriate classpath, providing relevant memory settings etc. I prefer using classworlds (which is used by Maven) to bootstrap my application and simplify writing of start scripts.

conf directory contains configuration files for your application as well as logging configuration files like log4j etc. This directory I add on classpath to make it easier to access configuration resources at runtime.

lib directory contains all the dependency jars a well as jar file for your code.

log is where your logging configuration will point to output log files.

Note that this structure is good for standalone server like applications. Also having a bin directory and run scripts allows you to add this directory to PATH on Windows / Linux to ensure you can run the application from anywhere.

If you are packaging a command line utility, simple shaded jar may work for you. Personally, I am not the biggest fan of java -jar application.jar

于 2013-11-14T11:37:16.510 に答える
2

質問は広すぎて包括的に答えることができませんが、実際の Maven 展開の例を提供したいと思います。

すべての主要なアプリケーション サーバー用の maven プラグインがあります。彼らは、ローカルおよびリモート展開のターゲットを定義しています。そのようなプラグインの 1 つがjboss-as-maven pluginです。デプロイ プロパティ (IP、ポートなど) は、.pomコマンド ラインで、またはコマンド ラインから直接定義できます。

mvn jboss-as:deploy -Dpassword=mypassword

アプリケーションの展開に特化したcargo プラグインもあります。

于 2013-11-14T11:33:26.950 に答える