Jaybanuan's Blog

どうせまた調べるハメになることをメモしていくブログ

PythonのYAML (PyYAML) の情報源

PythonYAML (PyYAML) の調べものをする際の情報源を集めておく。 デファクトの割には、どの情報が正しいのか(最新なのか)が分かりにくかったので。

結局、APIリファレンスが見つからなかったので、GitHubからソースコードを取得して眺めた。

自分のVS Codeの設定

{
    "editor.fontFamily": "'MS Gothic', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
    "editor.renderWhitespace": "all",
    "files.associations": {
        "*.txt": "markdown"
    },
    "files.autoGuessEncoding": true,
    "workbench.colorCustomizations": {
        "editorWhitespace.foreground": "#00B000"
    }
}

MS Gothicは、Windowsでどこでも利用できる等幅フォントなので、これを利用している。 どうもeditor.FontFamilyはCSSのfont-familyに対応付けられているらしく、CSSの仕様に従ってカンマ区切りでfallbackを指定するようだ。

参考

JavaでgRPC

はじめに

JavaのgRPCで、足し算(add)と合計(sum)を計算するサービスを作ってみる。

ディレクトリ構成

.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- redj
    |   |       `-- grpc
    |   |           |-- CalcClient.java
    |   |           `-- CalcService.java
    |   `-- proto
    |       `-- calc.proto
    `-- test
        `-- java
            `-- redj
                `-- grpc
                    |-- GrpcServerRule.java
                    |-- GrpcTest.java
                    `-- ManagedChannelRule.java

ソースコード

pom.xml

.protoをコンパイルしてJavaコードを吐き出すプラグインprotobuf-maven-pluginを利用する。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>redj-grpc</groupId>
    <artifactId>redj-grpc</artifactId>
    <version>1.0-SNAPSHOT</version>    
    <packaging>jar</packaging>
    
    <properties>
        <!-- configurations -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        
        <!-- plugin versios -->
        <os-maven-plugin.version>1.5.0.Final</os-maven-plugin.version>
        <protobuf-maven-plugin.version>0.5.0</protobuf-maven-plugin.version>
        
        <!-- dependency versions -->
        <junit.version>4.12</junit.version>
        <hamcrest.version>1.3</hamcrest.version>
        <grpc.version>1.6.1</grpc.version>
        <protobuf.version>3.3.0</protobuf.version>
    </properties>
    
    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>${os-maven-plugin.version}</version>
            </extension>
        </extensions>

        <pluginManagement>
            <plugins>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>${protobuf-maven-plugin.version}</version>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
        
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty</artifactId>
            <version>${grpc.version}</version>
        </dependency>
            
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>${grpc.version}</version>
        </dependency>
            
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>${grpc.version}</version>
        </dependency>
    </dependencies>
</project>

src/main/proto/calc.proto

gRPCのIDL。 …というよりは、データシリアライズを担当するProtocol Buffersのメッセージ定義という言い方が近いかも。 ここでは、足し算を行うAddと、合計を計算するSumの2のRPCを定義している、

syntax = "proto3";

option java_multiple_files = true;
option java_package = "redj.grpc.calc";
option java_outer_classname = "CalcProto";

package calc;

// The calc service
service Calc {
    // add
    rpc Add (AddRequest) returns (IntResponse);

    // sum
    rpc Sum (SumRequest) returns (IntResponse);
}

// The response containing the single int value.
message IntResponse {
    int32 value = 1;
}

// The request containing 2 int operands.
message AddRequest {
    int32 x = 1;
    int32 y = 2;
}

// The request containing int values.
message SumRequest {
    repeated int32 values = 1;
}

これをコンパイルすると、以下のクラスのソースが生成される。

  • target/generated-sources/protobuf/java
    • redj/grpc/calc/SumRequest.java
    • redj/grpc/calc/IntResponseOrBuilder.java
    • redj/grpc/calc/IntResponse.java
    • redj/grpc/calc/SumRequestOrBuilder.java
    • redj/grpc/calc/CalcProto.java
    • redj/grpc/calc/AddRequest.java
    • redj/grpc/calc/AddRequestOrBuilder.java
  • target/generated-sources/protobuf/grpc-java
    • redj/grpc/calc/CalcGrpc.java

生成されるソースのパッケージやクラス名は、calc.proto中のoption java_xxxで調整している。

src/main/java/redj/grpc/CalcService.java

足し算と合計を行うサービス。 サービスは、calc.protoから生成されたクラスを利用して実装する。 レスポンスの組み立てと送信が少々野暮ったい。

package redj.grpc;

import io.grpc.stub.StreamObserver;
import java.util.List;
import redj.grpc.calc.AddRequest;
import redj.grpc.calc.CalcGrpc;
import redj.grpc.calc.IntResponse;
import redj.grpc.calc.SumRequest;

public class CalcService extends CalcGrpc.CalcImplBase {

    @Override
    public void add(AddRequest request, StreamObserver<IntResponse> responseObserver) {
        System.out.println("calc add");

        IntResponse response = IntResponse
                .newBuilder()
                .setValue(request.getX() + request.getY())
                .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }

    @Override
    public void sum(SumRequest request, StreamObserver<IntResponse> responseObserver) {
        System.out.println("calc sum");

        IntResponse response = IntResponse
                .newBuilder()
                .setValue(sum(request.getValuesList()))
                .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }

    private int sum(List<Integer> values) {
        return values
                .stream()
                .mapToInt(value -> value)
                .sum();
    }
}

src/main/java/redj/grpc/CalcClient.java

クライアントも、calc.protoから生成されたクラスを利用して実装する。

package redj.grpc;

import io.grpc.ManagedChannel;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import redj.grpc.calc.AddRequest;
import redj.grpc.calc.CalcGrpc;
import redj.grpc.calc.IntResponse;
import redj.grpc.calc.SumRequest;

public class CalcClient {

    private final CalcGrpc.CalcBlockingStub stub;

    public CalcClient(ManagedChannel managedChannel) {
        this.stub = CalcGrpc.newBlockingStub(managedChannel);
    }

    public int add(int x, int y) {
        AddRequest request = AddRequest
                .newBuilder()
                .setX(x)
                .setY(y)
                .build();

        IntResponse response = stub.add(request);

        return response.getValue();
    }

    public int sum(int... values) {
        SumRequest request = SumRequest
                .newBuilder()
                .addAllValues(toList(values))
                .build();

        IntResponse response = stub.sum(request);

        return response.getValue();
    }

    private List<Integer> toList(int... values) {
        return Arrays
                .stream(values)
                .mapToObj(value -> value)
                .collect(Collectors.toList());
    }
}

src/test/java/redj/grpc/GrpcTest.java

gRPC用の組み込みサーバを立ち上げて、クライアントからアクセスするテスト。 サーバの起動停止はJUnitのRuleの機能を利用して、GrpcServerRuleというクラス内に隠蔽。 同様にサーバへの接続は、ManagedChannelRuleというクラス内に隠蔽。 ただし、複数のRuleの実行順序は未定義なので、RuleChainを利用して実行順序を指定する。

ちなみに、JUnitのRuleとは、@Before/@Afterの代替手段らしい。 たしかに、テストの前処理/後処理をRuleとしてテストクラスから切り離すとテストコードの見通しが良くなるし、他のテストでもRuleが再利用できて便利そう。

package redj.grpc;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;

public class GrpcTest {

    public GrpcServerRule grpcServerRule = new GrpcServerRule(8080, new CalcService());

    public ManagedChannelRule managedChannelRule = new ManagedChannelRule("localhost", 8080);

    @Rule
    public RuleChain ruleChain = RuleChain
            .outerRule(grpcServerRule)
            .around(managedChannelRule);

    @Test
    public void test() throws Exception {
        CalcClient calcClient = new CalcClient(managedChannelRule.getManagedChannel());
        System.out.println("add: " + calcClient.add(1, 2));
        System.out.println("sum: " + calcClient.sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
    }
}

src/test/java/redj/grpc/GrpcServerRule.java

サーバの起動/停止を、JUnitのRuleの一つであるTestWatcherを利用して実装する。

package redj.grpc;

import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import java.io.IOException;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

public class GrpcServerRule extends TestWatcher {

    private final Server server;

    public GrpcServerRule(int port, BindableService... bindableServices) {
        ServerBuilder serverBuilder = ServerBuilder.forPort(port);

        for (BindableService bindableService : bindableServices) {
            serverBuilder.addService(bindableService);
        }

        this.server = serverBuilder.build();
    }

    @Override
    protected void starting(Description description) {
        System.out.println("start the server");

        try {
            server.start();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    @Override
    protected void finished(Description description) {
        System.out.println("stop the server");

        if (server != null) {
            server.shutdownNow();
        }
    }
}

src/test/java/redj/grpc/ManagedChannelRule.java

クライアントとサーバの接続/切断を、JUnitのRuleの一つであるTestWatcherを利用して実装する。

package redj.grpc;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.util.concurrent.TimeUnit;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

public class ManagedChannelRule extends TestWatcher {

    private final String host;

    private final int port;

    private ManagedChannel managedChannel;

    public ManagedChannelRule(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public ManagedChannel getManagedChannel() {
        return managedChannel;
    }

    @Override
    protected void starting(Description description) {
        System.out.println("connect to the server");

        this.managedChannel = ManagedChannelBuilder
                .forAddress(host, port)
                .usePlaintext(true)
                .build();
    }

    @Override
    protected void finished(Description description) {
        System.out.println("disconnect from the server");

        if (managedChannel != null) {
            managedChannel.shutdownNow();
            
            try {
                managedChannel.awaitTermination(5, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    }
}

ManagedChannelはそこそこ高機能で、スレッドーセーフだったり、再接続(リトライ?)機能があったりするみたい。 JavaDocを見ても詳しい仕様は読み取れないので、ソースを読まないと詳細は分からなさそう。

ビルドとテスト

ソースコード中のSystem.out.println()が想定通りに出力されていることを確認する。

$ mvn clean test
(略)
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running redj.grpc.GrpcTest
start the server
connect to the server
calc add
add: 3
calc sum
sum: 55
disconnect from the server
stop the server
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.975 sec
(略)

参考

gRPCとProtocol Buffersの参考情報

はじめに

自分の勉強用のメモです。

リンク

JSON-Bを利用してJSONをPOJOにバインディング

はじめに

JSON-Bを利用してJSONPOJOにバインドするサンプル。 JSON-Bの実装は、参照実装のYassonを利用。

ディレクトリ構成

.
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- redj
    |           `-- jsonb
    |               `-- binding
    |                   |-- Person.java
    |                   `-- Root.java
    `-- test
        |-- java
        |   `-- redj
        |       `-- jsonb
        |           `-- JsonbTest.java
        `-- resources
            `-- redj
                `-- jsonb
                    `-- data.json

ソースコード

src/test/resources/redj/jsonb/data.json

テストデータとして、以下のJSONを利用。

{
    "persons": [
        {
            "first-name": "Ichiro",
            "last-name": "Yamada",
            "age": 20
        },
        {
            "first-name": "Taro",
            "last-name": "Suzuki",
            "age": 30
        }
    ]
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>redj-jsonb</groupId>
    <artifactId>redj-jsonb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
   
  
    <properties>
        <!-- configurations -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        
        <!-- dependency versions -->
        <junit.version>4.12</junit.version>
        <javax.json.bind-api.version>1.0</javax.json.bind-api.version>
        <yasson.version>1.0</yasson.version>
        <javax.json.version>1.1</javax.json.version>
    </properties>
        
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>javax.json.bind</groupId>
            <artifactId>javax.json.bind-api</artifactId>
            <version>${javax.json.bind-api.version}</version>
        </dependency>
                    
        <dependency>
            <groupId>org.eclipse</groupId>
            <artifactId>yasson</artifactId>
            <version>${yasson.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>${javax.json.version}</version>
        </dependency>    
    </dependencies>
</project>

src/main/java/redj/jsonb/binding/Root.java

テストデータのJSONのルートにあたるクラス。

package redj.jsonb.binding;

import java.util.List;
import javax.json.bind.annotation.JsonbProperty;

public class Root {

    @JsonbProperty(value = "persons")
    public List<Person> persons;
}

src/main/java/redj/jsonb/binding/Person.java

テストデータのJSONの配列personsの各要素にあたるクラス。

package redj.jsonb.binding;

import javax.json.bind.annotation.JsonbProperty;

public class Person {

    @JsonbProperty(value = "first-name")
    public String firstName;

    @JsonbProperty(value = "last-name")
    public String lastName;

    @JsonbProperty(value = "age")
    public int age;
}

src/test/java/redj/jsonb/JsonbTest.java

data.jsonPOJOに変換し、そのPOJOをもう一度JSONに変換して標準出力に出力するテスト。 標準出力に出力する際に、整形したJSONになるようにJsonConfigを設定している。

テストの最後で改行を出力しているのは、単にMavenの出力の見た目を整えるため。

package redj.jsonb;

import java.io.IOException;
import java.io.InputStream;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import org.junit.Test;
import redj.jsonb.binding.Root;

public class JsonbTest {

    @Test
    public void test() throws IOException {
        try (InputStream in = getClass().getClassLoader().getResourceAsStream("redj/jsonb/data.json")) {
            // configure JSON-B
            JsonbConfig jsonbConfig = new JsonbConfig()
                    .withFormatting(true);

            // create Jsonb instance
            Jsonb jsonb = JsonbBuilder.create(jsonbConfig);

            // deserialize and serialize 
            Root root = jsonb.fromJson(in, Root.class);
            jsonb.toJson(root, System.out);

            // I want a newline !!
            System.out.println();
        }
    }
}

ビルドとテスト

$ mvn clean test
(略)
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running redj.jsonb.JsonbTest

{
    "persons": [
        {
            "age": 20,
            "first-name": "Ichiro",
            "last-name": "Yamada"
        },
        {
            "age": 30,
            "first-name": "Taro",
            "last-name": "Suzuki"
        }
    ]
}
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.682 sec
(略)

参考

EclipseLink Moxyを利用してJSONをPOJOにバインド

はじめに

2017/7/7にJSON-BがFinal Releaseになったので、もはやJSON-Bでいいんだけど、過去の自分の作業記録ということで。

EclipseLink Moxyを利用してJSONPOJOにバインドするサンプル。 JAXBを利用するので最初は違和感があったけど、慣れればそれほど気にならない。

ディレクトリ構成

.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- redj
    |   |       `-- moxy
    |   |           |-- JaxbJson.java
    |   |           `-- binding
    |   |               |-- Person.java
    |   |               `-- Root.java
    |   `-- resources
    |       `-- META-INF
    |           `-- services
    |               `-- javax.xml.bind.JAXBContext
    `-- test
        |-- java
        |   `-- redj
        |       `-- moxy
        |           `-- JaxbJsonTest.java
        `-- resources
            `-- redj
                `-- moxy
                    `-- data.json

ソースコード

src/test/resources/redj/moxy/data.json

テストデータとして、以下のJSONを利用。

{
    "persons": [
        {
            "first-name": "Ichiro",
            "last-name": "Yamada",
            "age": 20
        },
        {
            "first-name": "Taro",
            "last-name": "Suzuki",
            "age": 30
        }
    ]
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>redj-moxy</groupId>
    <artifactId>redj-moxy</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    
  
    <properties>
        <!-- configurations -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        
        <!-- dependency versions -->
        <junit.version>4.12</junit.version>
        <eclipselink.version>2.7.0</eclipselink.version>
    </properties>
        
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.moxy</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
    </dependencies>
</project>

src/main/java/redj/moxy/JaxbJson.java

JSON <=> POJOの変換を行うクラスで、ほぼJAXBのラッパー。 MarshallerとUnmarshallerにEclipseLink固有のプロパティを設定している点がポイント。

package redj.moxy;

import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

public class JaxbJson {

    private final JAXBContext jaxbContext;

    public JaxbJson(Class<?>... classes) throws JAXBException {
        this.jaxbContext = JAXBContext.newInstance(classes);
    }

    public <T> T read(InputStream in, Class<T> clazz) throws JAXBException {
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setProperty("eclipselink.json.include-root", false);
        unmarshaller.setProperty("eclipselink.media-type", "application/json");
        JAXBElement<T> jaxbElement = (JAXBElement) unmarshaller.unmarshal(new StreamSource(in), clazz);

        return jaxbElement.getValue();
    }

    public void write(OutputStream out, Object object) throws JAXBException {
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty("eclipselink.json.include-root", false);
        marshaller.setProperty("eclipselink.media-type", "application/json");
        marshaller.marshal(object, out);
    }
}

src/main/java/redj/moxy/binding/Root.java

テストデータのJSONのルートにあたるクラス。

package redj.moxy.binding;

import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Root {

    @XmlElement(name = "persons")
    public List<Person> persons;
}

src/main/java/redj/moxy/binding/Person.java

テストデータのJSONの配列personsの各要素にあたるクラス。

package redj.moxy.binding;

import javax.xml.bind.annotation.XmlElement;

public class Person {

    @XmlElement(name = "first-name")
    public String firstName;

    @XmlElement(name = "last-name")
    public String lastName;

    @XmlElement(name = "age")
    public int age;
}

src/main/resources/META-INF/services/javax.xml.bind.JAXBContext

JAXBの実装をEclipseLink Moxyに切り替えるためのファクトリクラスの指定。

org.eclipse.persistence.jaxb.JAXBContextFactory

src/test/java/redj/moxy/JaxbJsonTest.java

data.jsonPOJOに変換し、そのPOJOをもう一度JSONに変換して標準出力に出力するテスト。 テストの最後で改行を出力しているのは、単にMavenの出力の見た目を整えるため。

package redj.moxy;

import java.io.InputStream;
import org.junit.Test;
import redj.moxy.binding.Root;

public class JaxbJsonTest {

    @Test
    public void test() throws Exception {
        try (InputStream in = getClass().getClassLoader().getResourceAsStream("redj/moxy/data.json")) {
            JaxbJson jaxbJson = new JaxbJson(Root.class);
            Root root = jaxbJson.read(in, Root.class);
            jaxbJson.write(System.out, root);

            System.out.println();   // I want a newline !!
        }
    }
}

ビルドとテスト

$ mvn clean install
(略)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running redj.moxy.JaxbJsonTest
{"persons":[{"first-name":"Ichiro","last-name":"Yamada","age":20},{"first-name":"Taro","last-name":"Suzuki","age":30}]}
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.741 sec

(略)

参考

GlassFish 4で実質的なデプロイメントデスクリプタを生成

アノテーションを利用してJava EEの開発をしていると、時々デプロイメントデスクリプタを参照して、アプリ全体の整合性を確認したくなる。 GlassFish 4では、システムプロパティwriteout.xmltrueに設定してアプリをデプロイすることで、ディレクト[DOMAIN_HOME]/generated/xml/[アプリ名]に実質的(‘Effective’)なデプロイメントデスクリプタが生成される。 イメージ的には、mvn help:effective-pomのような感じ。

システムプロパティの設定コマンドは以下。

$ asadmin create-system-properties writeout.xml=true

設定後、GlassFishの再起動を忘れずに。

参考