包装及运行带有弹簧的依赖Java应用程序 [英] Package and run a Java application with spring dependencies

查看:125
本文介绍了包装及运行带有弹簧的依赖Java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建了有一堆依赖关系(Apache的共享库等),以及对Spring框架,从而有一堆依赖关系的依赖一个独立的Java应用程序。

I built a stand-alone Java application that has a bunch of dependencies (Apache Commons libs, etc) as well as a dependency on the Spring framework, which in turn has a bunch of dependencies.

我建立了这个在Eclipse中,它运行良好。现在我需要将它部署到生产,所以我试图找出最好的方式来与所有的依赖关系打包以及如何调用连的东西(它会从从命令行调用)。

I built this in Eclipse, where it runs fine. Now I need to deploy it to production and so I'm trying to figure out the best way to package it with all dependencies and also how to even invoke the thing (it will be invoked from the command line).

蛮力的方法是将我的项目导出为一个罐子,发现所有的依赖罐子(和它们的依赖!),将它们复制到公共目录,写一个shell脚本,其中包括每一个在类路径和运行它。显然,这似乎愚蠢和乏味的。

The brute-force way would be to export my project as a jar, find all the dependent jars (and their dependencies!), copy them to a common directory, write a shell script that includes every one on the classpath and run it. Obviously that seems stupid and tedious.

我应该使用Ant,Maven的?我是否应该包中的所有相关的春天罐子成一个大文件?在处理这个任何提示将是有益的。

Should I use Ant, Maven? Should I package all of the dependent Spring jars into one big file? Any tips on dealing with this would be helpful.

推荐答案

Java的部署仍是个愚蠢而乏味的2009年因此常见的选项是写这个小脚本。如果你把所有的JAR文件到一个目录(比如的lib \\ ),你可以使用自动构建classpath中常见的脚本(请参阅这个博客条目)。我建议在开始添加 CD / D%〜DP0 cd到脚本的目录。

Java deployment is still stupid and tedious in 2009. So the usual option is to write this small script. If you put all your JARs into one directory (say, lib\), you can use a common script which builds the classpath automatically (see this blog entry). I suggest to add a cd /d %~dp0 at the beginning to cd into the script's directory.

2的Maven有一个插件,它可以组装您的应用程序在一个超级JAR( MVN装配:装配)。这工作,除非您使用DB2 JCC驱动程序(其中包含被转换包com.ibm 的COM.ibm的 - > ClassNotFoundException的)

Maven 2 has a plugin which can assemble your application in one "super JAR" (mvn assembly:assembly). This works unless you use the DB2 JCC driver (which contains "COM.ibm." packages which get converted to com.ibm. -> ClassNotFoundException).

最后一个解决办法,如果你已经是ANT的build.xml这工作,就是要打开所有相关的JAR文件,并创建一个超级JAR自己。

The last solution, if you have already an ANT build.xml which works, is to unpack all the dependent JARs and create a "super JAR" yourself.

这篇关于包装及运行带有弹簧的依赖Java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆