zoukankan      html  css  js  c++  java
  • Distributing Jython Apps in a Single JAR file

    EnigmaCurry

    Distributing Jython Apps in a Single JAR file

    May 20, 2009 at 02:20 PM | categories:

    python, java
    | 12 Comments and 1 Reaction

     

    I've been writing a lot of one-off type applications at work lately, which is always kind of a joy for me because these sorts of applications don't need to be maintained or supported in any way, which means I can write them however I want.

    So I write them in Python :)

    Jython allows me to interface with all the plethora of Java libraries that we use at work, and it lets me program in a language that not only I can tolerate, but one that I respect and love.

    But even though these are one-off applications, they still need to be easy to use, and in some cases I won't even be the one running the application. I want these applications to just work damnit.

    So, packaging my Jython application into a single executable jar file that contains all of the third party dependancies inside is my goal. I want to send the user the jar file, have them double click on it, and have it immediately start running. It can't get a whole lot easier than that.

    The Jython wiki has a page about doing something along these lines. The recipe there called the Jar Method works quite well. The one drawback that it has is that all of the Java dependancies need to be exploded into the main jar root, which when you're dealing with dozens of jar dependancies, it can start to get tedious, messy, and in some cases will even violate the license of a particular library.

    One-Jar is a special class loader that can load a jar file that is inside of another jar file, something that the regular class loader from Sun is incapable of doing. Using One-Jar lets my application reside inside of a jar file and contain all my dependancies as seperate jar files inside the main jar file.

    I've created a sample project that shows how I normally create a new Jython project hosted inside a single jar file with One-Jar. You'll need the following tools to check out the project:

    Check out the project like so:

     git clone git://github.com/EnigmaCurry/Single-JAR-Jython-Example.git
    

    Build the project:

    cd single-jar-jython-example
    
    ant
    

    Run the example by double clicking it or via the command line:

     java -jar JythonExcelExample.jar
    

    This is just a demonstration app, it doesn't do a whole lot, it outputs an excel file in the current directory listing some computer parts. The point of the application is to show how Jython can integrate with existing Java third-party libraries (in this case Apache POI.)

    Instructions for basing your own application on this example are contained inside the README.txt file.

  • 相关阅读:
    Web性能压力测试工具之ApacheBench(ab)详解
    微服务监控之三:Prometheus + Grafana Spring Boot 应用可视化监控
    Sentinel-dashboard
    Java8之默认方法和静态接口方法
    蓝绿部署、红黑部署、AB测试、灰度发布、金丝雀发布、滚动发布的概念与区别
    JAVA8 十大新特性详解
    Java链式方法 连贯接口(fluent interface)
    分布式计算概念一览
    Gradle学习
    Java堆外内存之七:JVM NativeMemoryTracking 分析堆外内存泄露
  • 原文地址:https://www.cnblogs.com/lexus/p/2516839.html
Copyright © 2011-2022 走看看