1 安装方法
可以直接从jME网站下载jar包,也可以下载源码自己编译。直接下载jar的包没有源代码和javadoc,不过可以自己编译,用maven把三个包都生成。
1.1 获取源码
# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://jmonkeyengine.googlecode.com/svn/trunk/ jmonkeyengine-read-only
安装方法可以参考网址:http://www.jmonkeyengine.com/wiki/doku.php?id=setting_up_eclipse_to_build_jme_2、http://www.jmonkeyengine.com/wiki/doku.php?id=downloading_and_installing_jme_2.x
也可以用CVS,安装方法可以参考网址:http://www.jmonkeyengine.com/wiki/doku.php?id=setting_up_eclipse_to_build_jme/有详细介绍。
svn比cvs新一些。
1.2 用maven编译
下载下来的项目不是maven项目,首先得构造成maven项目。如果装了Q4E插件可以用上图所示的方法。然后把src目录和test目录分别拖到src/main/java和src/test/java包下。
也可以用脚本:
mvn archetype:generate -DgroupId=com.mypackage -DartifactId=jme-sample
修改pom.xml文件,加上source和javadoc插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<outputEncoding>GBK</outputEncoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
需要注意的是要用jdk1.5来编译。
要将依赖包加入到本地maven库(上传到私服比较简单):
mvn install:install-file -Dfile=lib/lwjgl/lwjgl.jar -DgroupId=org.lwjgl -DartifactId=lwjgl -Dversion=2.0rc1 -Dpackaging=jar
mvn install:install-file -Dfile=lib/lwjgl/lwjgl_util.jar -DgroupId=org.lwjgl -DartifactId=lwjgl_util -Dversion=2.0rc1 -Dpackaging=jar
mvn install:install-file -Dfile=lib/lwjgl/lwjgl_util_applet.jar -DgroupId=org.lwjgl -DartifactId=lwjgl_util_applet -Dversion=2.0rc1 -Dpackaging=jar
mvn install:install-file -Dfile=lib/lwjgl/jinput.jar -DgroupId=net.java.dev.jinput -DartifactId=jinput -Dversion=SNAPSHOT -Dpackaging=jar
mvn install:install-file -Dfile=lib/jorbis/jorbis-0.0.17.jar -DgroupId=jorbis -DartifactId=jorbis -Dversion=0.0.17 -Dpackaging=jar
mvn install:install-file -Dfile=lib/jogl/jogl.jar -DgroupId=net.java.dev.jogl -DartifactId=jogl -Dversion=1.1.1 -Dpackaging=jar
mvn install:install-file -Dfile=lib/jogl/gluegen-rt.jar -DgroupId=net.java.dev.gluegen -DartifactId=gluegen-rt -Dversion=1.0b06 -Dpackaging=jar
jME用了外部dll库,需要引进来。可以在运行程序是加上“-Djava.library.path="dll库的路径"”,Eclipse中可以这么加:
在每个main运行时都得配置,挺麻烦。在build path中指定只需配一次就可以了,如图:
然后用mvn package就可以打包了。
1.3 构建自己的项目
新建maven项目,修改pom.xml
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){var content=codeElement.innerText;if(window.clipboardData==null){window.alert("您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function LineNumberVisible(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tet</groupId>
<artifactId>tet</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>tet</name>
<url>http://maven.apache.org</url>
<properties>
<lwjgl.version>2.1</lwjgl.version>
<main.class>tet.App</main.class>
<jme2.home>D:/src_doc/jME2_0_1-Stable
</jme2.home>
<lwjgl.natives>${jme2.home}/lib/lib/lwjgl/native
</lwjgl.natives>
</properties>
<dependencies>
<dependency>
<groupId>jme</groupId>
<artifactId>jme</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<!--
we ned to add lib/jme-colladabinding.jar to the classpath for
compiling
-->
<groupId>com.jmonkeyengine.collada</groupId>
<artifactId>jme-collada</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jme-colladabinding.jar
</systemPath>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl_util_applet</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl_util</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jogl</groupId>
<artifactId>jogl</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.java.dev.gluegen</groupId>
<artifactId>gluegen-rt</artifactId>
<version>1.0b06</version>
</dependency>
<dependency>
<groupId>net.java.dev.jinput</groupId>
<artifactId>jinput</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jorbis</groupId>
<artifactId>jorbis</artifactId>
<version>0.0.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin
</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<outputEncoding>GBK</outputEncoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<executions>
<execution>
<id>bundle-project-sources</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<systemProperties>
<systemProperty>
<key>org.lwjgl.librarypath</key>
<value>${lwjgl.native}</value>
</systemProperty>
</systemProperties>
<mainClass>${main.class}</mainClass>
<argument>-classpath</argument>
<!--
automatically creates the classpath using all project
dependencies, also adding the project build directory
-->
<classpath />
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>linux</id>
<activation>
<os>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<properties>
<lwjgl.native>${lwjgl.natives}/linux
</lwjgl.native>
</properties>
</profile>
<profile>
<id>macosx</id>
<activation>
<os>
<family>unix</family>
<name>mac os x</name>
</os>
</activation>
<properties>
<lwjgl.native>${lwjgl.natives}/macosx
</lwjgl.native>
</properties>
</profile>
<profile>
<id>windows</id>
<activation>
<os>
<arch>x86</arch>
<family>windows</family>
</os>
</activation>
<properties>
<lwjgl.native>${lwjgl.natives}/windows
</lwjgl.native>
</properties>
</profile>
</profiles>
</project>
这里需要添加依赖的jme包:
<dependency>
<groupId>jme</groupId>
<artifactId>jme</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
将jme-2.0-SNAPSHOT-javadoc.jar和jme-2.0-SNAPSHOT-sources.jar加到maven库里可以方便的查看source和javadoc,编程时会很方便。
要根据自己的环境修改以下属性:
<properties>
<lwjgl.version>2.1</lwjgl.version>
<main.class>tet.App</main.class>
<jme2.home>D:/src_doc/jME2_0_1-Stable
</jme2.home>
<lwjgl.natives>${jme2.home}/lib/lib/lwjgl/native
</lwjgl.natives>
</properties>
要想直接在Eclipse里run需要配置Native library path,如图:
脚本运行的话别忘了加上“-Djava.library.path="dll库的路径"”。
如果报一下错误的话,说明没有正确配置Native library path:
Native library not set - go to
http://www.jmonkeyengine.com/wiki/doku.php?id=no_lwjgl_in_java.library.path
for details.
java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
at org.lwjgl.Sys.loadLibrary(Sys.java:81)
at org.lwjgl.Sys.<clinit>(Sys.java:98)
at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
at com.jme.system.lwjgl.LWJGLPropertiesDialog$ModesRetriever.run(LWJGLPropertiesDialog.java:682)
at com.jme.app.AbstractGame.getAttributes(AbstractGame.java:252)
at com.jme.app.BaseGame.start(BaseGame.java:67)
at tet.App.main(App.java:23)
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){var content=codeElement.innerText;if(window.clipboardData==null){window.alert("您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function LineNumberVisible(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i