mvnでlwjglなメモ

ちょっとOpenGLなツールを作るべくjavaで作業開始。

プロジェクト作成

> mvn archetype:create -DgroupId=jp.ousttrue -DartifactId=mygl
> cd mygl
> vim pom.xml

lwjglなpom.xml
http://lwjgl.org/wiki/index.php?title=LWJGL_use_in_Maven
をベースに追記。

<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>jp.ousttrue</groupId>
  <artifactId>mygl</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mygl</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <lwjgl.version>2.7.1</lwjgl.version>
    <entrypoint>${pom.groupId}.App</entrypoint>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>org.lwjgl</groupId>
              <artifactId>lwjgl-native</artifactId>
              <version>${lwjgl.version}</version>
              <type>jar</type>
              <outputDirectory>${project.build.directory}/libs/natives</outputDirectory>
              <overWrite>true</overWrite>
            </artifactItem>
          </artifactItems>
        </configuration>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <configuration>
          <mainClass>${entrypoint}</mainClass>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>${lwjgl.version}</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-util</artifactId>
      <version>${lwjgl.version}</version>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>lwjgl</id>
      <name>lwjgl</name>
      <url>http://adterrasperaspera.com/lwjgl</url>
    </repository>
  </repositories>

</project>

ビルド

> mvn install

実行

> set PATH=target\libs\natives\windows
> mvn exec:java

forkしないのでsystemPropertyからjava.library.pathを渡すことができない。事前にdllにパスを通している。