onejar

onejar-maven-plugin把java类与lib打包为一个可运行jar

大兔子大兔子 提交于 2019-12-06 18:35:18
1、问题背景 我们有时要开发一个Java Application,就是main来直接运行的那种,虽然有好多工具可以帮助我们打为jar。 但会有以下两个问题: 第一种是需要lib目录依赖一起来运行。(需要依赖文件,一个jar不可以运行) 第二种就是是把其它依赖的jar解开和你的类放在一个jar中。(框架的限制,包依赖之间的冲突,解压替换内容的过程产生类与资源的混乱) 第一种的问题显而易见需要copy太多东西(lib/*.jar)太麻烦。 第二种虽然可以做到一个jar运行的效果,但因为是解开再合再一起,尤其是jar中类有冲突时将和你在ide中不解开执行的效果不一样。(如eclipse可以运行,打包出来就不可以运行) 2、用One-JAR来解决 这个工具很好的解决了这一点,它相当于做一了一个启动壳。可以不改变你的jar与依赖的jar包,也不用解开。 简单理解就是jar中有jar。运行可以达到ide或配类路径运行一样的效果。 One-JAR有maven下的插件onejar-maven-plugin,所以对于maven的jar工程来说打包很方便。 pom.xml只需要加入以下plugin内容 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId>

Using one-jar to build one jar file

烂漫一生 提交于 2019-12-06 16:45:10
I'm trying to use one-jar to generate one jar file that contains clojure jar file and java class file: Creating one jar file that for execution from Java/Clojure Following the instruction , I could generate directories using one-jar-appgen-0.97.jar . As instructed, I replaced the java source, and added the ThingOne-1.0.0-SNAPSHOT-standalone.jar Running ant , it builds jar file without an error, but I got error messages when I try to execute the jar file. java -jar build/test-one-jar.jar test_one_jar main entry point, args=[] Hello from Java! Exception in thread "main" java.lang.reflect

Classpath resources inside one-jar packaged via sbt

别等时光非礼了梦想. 提交于 2019-12-01 21:04:09
I have a project that is build using SBT which packages a single jar using the one-jar plugin. That project contains a bunch of json files in src/main/resources/fixture which I used to access via new java.io.File(App.getClass.getResource("/fixture").getFile Unfortunately this doesn't work any longer since no Resource is returned. I think one-jar uses a special classloading mechanism? Whats the best way to solve this? I think one-jar uses a special classloading mechanism? Yes, this must be true since there is no standardized way to load classes that packaged into dependency jar that is in turn