2014年11月16日日曜日

UbuntuでJSONの整形 (2)

UbuntuでJSONの整形で紹介した方法では、
日本語がユニコードにエスケープされてしまうので回避方法を紹介します。(キーのソートも追加しました)

JsonPrettyPrint.pyを作成
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json

jsonStr = raw_input()
prettyPrint = json.loads(jsonStr)
print json.dumps(prettyPrint, indent=4, ensure_ascii=False, sort_keys=True)

整形する場合は

$ python JsonPrettyPrint.py
{"キー":"値"}

{
    "キー": "値"
}

でできます。

sample : JsonPrettyPrint.py

2014年11月8日土曜日

Maven projectで、Maven project以外のjarを参照する方法

Local Repository(localRepo)を作成し、jarを配置。
jarと同じ位置に、pomファイル(SampleSub-1.0.0.pom)を作成する。

- ファイル構成

  SampleMain
    |- pom.xml
    |- src
    |- localRepo
        |- sample
            |- sub
                |- SampleSub
                    |- 1.0.0
                        |- SampleSub-1.0.0.pom
                        |- SampleSub-1.0.0.jar

- SampleSub-1.0.0.pom

  <project>
    <groupId>sample.sub</groupId>
    <artifactId>SampleSub</artifactId>
    <version>1.0.0</version>
  </project>

メインのpomにrepositoryとdependencyを追加する。

- pom.xml

  <project>
    ...

    <repositories>
      <repository>
        <id>local Repo</id>
        <url>file:${basedir}/localRepo</url>
      </repository>
    </repositories>

    <dependencies>
      <dependency>
        <groupId>sample.sub</groupId>
        <artifactId>SampleSub</artifactId>
        <version>1.0.0</version>
      </dependency>
    </dependencies>

  </project>