jip 0.2 released

As you may know, jip is a dependency management tool for Jython/Java development. It resolves and downloads Java packages from maven-compatible repositories. jip also follows some best practices, encouraging you to use a portable and standalone environment (virtualenv) for your Jython development.

It has been four months since the initial release. In version 0.2, I made following changes for you:

  • Improved console output format
  • Correct scope dependency management inheritance
  • Snapshot management, alpha
  • Environment independent configuration
  • Bug fixes

You can find the typical usage doc on github:
https://github.com/sunng87/jip

jip-0.2 has been published to pypi so you can install or upgrade it with:
easy_install -U jip

Please do remember to use it inside virtualenv!

Setting up soldat and gefr

本文介绍soldat服务器和gefr WSGI适配器的环境搭建,以及jip的基本使用。

安装python工具

virtualenv和pip是python开发的关键工具
sudo apt-get install python-virtualenv
sudo apt-get install python-pip

jython需要您手动下载安装。推荐安装到/usr/local/下,并建立软连接到/usr/local/bin/中,下文将假设您是这么做的。

创建虚拟jython环境

virtualenv -p /usr/local/bin/jython gefr-test
cd gefr-test
source bin/activate

安装jip

pip install jip

配置jip

在$HOME下创建文件.jip,内容为:

[repos:oss]
uri=http://oss.sonatype.org/content/repositories/snapshots/
type=remote

[repos:central]
uri=http://repo1.maven.org/maven2/
type=remote

[repos:local]
uri=/home/sun/.m2/repository/
type=local

安装soldat

配置完jip后,可以使用jip来安装soldat
jip install info.sunng.soldat:soldat:1.0-SNAPSHOT

文件将被下载到 javalib 目录中,您可以检查安装的正确性:
$ ls javalib/
log4j-1.2.16.jar slf4j-log4j12-1.6.1.jar
slf4j-api-1.6.1.jar soldat-1.0-SNAPSHOT.jar

安装gefr

pip install gefr==0.1dev2

创建一个简单的Python WSGI程序

创建test.py

from gefr import Gefr

def wsgiapp(environ, start_response):
    status = '200 OK'
    res_body = "<html><head><title>Welcome</title></head><body><h1>It works!</h1></body></html>"
    res_headers = [('Content-Type', 'text/html'),
            ('Content-Length', str(len(res_body)))]
    start_response(status, res_headers)
    return [res_body]

Gefr(wsgiapp, host='0.0.0.0', port=8000).start()

启动服务

使用jip附带的jython-all
jython-all test.py

打开浏览器,访问 http://localhost:8000/

用ab测试服务性能

$ ab -n 10000 -c 100 http://localhost:8000/

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:        gefr/0.1dev
Server Hostname:        localhost
Server Port:            8000

Document Path:          /
Document Length:        79 bytes

Concurrency Level:      100
Time taken for tests:   2.539 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1640000 bytes
HTML transferred:       790000 bytes
Requests per second:    3938.11 [#/sec] (mean)
Time per request:       25.393 [ms] (mean)
Time per request:       0.254 [ms] (mean, across all concurrent requests)
Transfer rate:          630.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       8
Processing:     9   25  22.4     21     239
Waiting:        9   25  22.4     21     239
Total:         13   25  22.3     21     239

Percentage of the requests served within a certain time (ms)
  50%     21
  66%     22
  75%     22
  80%     23
  90%     26
  95%     40
  98%     65
  99%    233
 100%    239 (longest request)

Good Luck!

jip 0.1

The original idea is to create a standalone jython environment, I took traditional Java tools, ant and ivy, to resolve Java dependencies. But the XMLs seem to be verbose and not pythonic. So I decide to create something like pip, that is, resolves and installs dependencies in a pythonic way. It is jip.

jip will automatically download jars and its non-optional runtime dependencies from Maven repositories. By default, jip will search your local repository and maven central repository for the requested artifact. Also, you can create a configuration file to overwrite this.

Virtualenv is required by jip. You must run jip within a standalone environment, created by virtualenv:
virtualenv -p /usr/local/bin/jython jython-env
cd jython-env
source bin/activate

Don’t forget to activate it.

Then download jip with pip:
pip install jip

Now you have pip for python and jip for java. To install a Java package, just type:
jip install <groupId>:<artifactId>:<version>

groupId+artifactId+version is known as the coordinate of a maven artifact. For example, you need spring-core in your jython development:
jip install org.springframework:spring-core:3.0.5.RELEASE

The jars will be stored in javalib directory:
ls javalib

commons-logging-1.1.1.jar     spring-core-3.0.5.RELEASE.jar
spring-asm-3.0.5.RELEASE.jar

And When you installed jip, I will provide you a jython-all command to include dependencies by default. So use jython-all instead of jython to run your program and the shell.

For traditional Java user, there is a resolve subcommand to download dependencies defined in a pom file. This is more maintainable, some of you may prefer this way to typing it one by one.
jip resolve pom.xml

To define custom repositories, place a dot file .jip in your home directory:

[jboss]
uri=http://repository.jboss.org/maven2/
type=remote

[local]
uri=/home/sun/.m2/repository/
type=local

[central]
uri=http://repo1.maven.org/maven2/
type=remote

You may have internal Nexus, just append to this file following the pattern.

Finally, a clean subcommand to remove everything you downloaded.

That’s all. You can find the project at:

Your feedback is appreciate. Fire an issue in github if you find any bugs or new ideas about this tool.