怎么引入java3d包,如何动态加载Java3D库?

I am finishing up a game that I developed using Java3D. Since Java3D does not come with the standard JRE, all of the people who I am giving this game to will have to download Java3D. Some of my friends are a little less computer savvy so I thought it would be a lot less work to just write the Jars to the disk and dynamically load them in Java. Is there a better solution to this? Or is dynamically loading the Jars the way to go?

I have installed Java3D on another computer of mine from here:

It was a pretty quick installation but it would be better if you didn't have to download anything at all. If they are only going to use Java3D for my game then it doesn't really seem logical for them to go through the trouble of downloading it.

Are there any more efficient solutions to this? Is dynamically loading the Jars just the way to go?

EDIT

Here is my problem simplified:

Java3D is not a standard part of Java, it is an extension that must be installed separately

Java3D consists of 3 Jar Files (j3core.jar, j3dutils, vecmath)

I want to be able to run my game on other computers without them having to download the Jar files

Now here is my simplified question:

How do I run Java3D on a computer that doesn't have Java3D installed? I want to write the Jar files to a CD, along with the game, and be able to play the game right off the CD, no installations no downloads. How can I do this?

解决方案

The jars are not platform specific, the native code in the dynamic libraries is. The dynamic libraries are already loaded as they are called for in code. If you take a look back at that code you will see that loadLibrary() does not ask for the extension. There is a reason for this, JNI (the Java Native Interface) looks for certain extensions based on what system it is running on. For this reason just package all the dynamic libraries where JNI can find it, such as right next to your application and JNI will take care of the rest.

Some code to point you in the right direction:

Blah.java

public class blah{

public native void meh();

public static void main(String args[]) {

meh();

}

}

static {

System.loadLibrary("thing");

}

Blah.cpp

#include

#include

#include "Blah.h"

JNIEXPORT void JNICALL Java_Blah_meh() {

cout << "Meh.";

}

Blah.cpp (with the Blah.h generated by the javah program) is compiled into a dynamic library for each major system (thing.dll, thing.dylib, thing.so). Blah.java is compiled into a .class file, toss it in a jar just for ease for execution.

Now for the important part, the layout of files!

ThingApp //that's a folder

|thing.dll

|thing.dylib

|thing.so

|Blah.jar

Put this on any system and JNI will find the right file for the system due to the extensions, load the library into memory, execute the code, and print out "Meh.". JNI finds the files because they are in the PATH environment variable (or the system equivalent). The PATH includes the folder the executed code/program is in, folders set with the java.library.path system property, and the folders included int he PATH variable itself.

Basically you just need to worry about the part about the PATH as everything else is done for you!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值