Getting Started With Java3D

Getting Started: Java 3D API Installation

Introduction

Before getting into the programming side of Java3D, we need to download and install the required libraries. For this guide I will be demonstrating how to import the Java3D API into Eclipse and Netbeans.

Downloads

Downloading your IDE

You may already have an IDE installed on your computer, this is fine. Providing it is either Eclipse or Netbeans, if it isn’t you may need to find another tutorial or figure this part out for yourself. It isn’t possible for me to do this same example for every IDE out there as I would be here forever so, I picked two of the most popular free IDE’s.

Downloading Eclipse
https://eclipse.org/downloads/

In my example I will be using Eclipse Neon, as this is currently the most recently available version of the software as of January 2017.

cdfaf02f6ebdd50a0b0fdd70d20520a9

Locate the download button and download the latest version.

Installing Eclipse is fairly simple after you download the installer run it and you will get the required files to run Eclipse.

413f922c80d27e77b5f2583beca8578e

Your folder structure should look somewhat similar to this. To run eclipse click the Eclipse application which has the Eclipse logo next to it.

Downloading NetBeans
https://netbeans.org/downloads/

If you’re new to programming/Java you will only require the Java SE version of NetBeans, if you already have the knowledge surrounding the other versions of NetBeans you can download one of the extended versions.

88be73f519d4b86eb4003cb72cd86e6d

Locate the download button and download the latest version.

Now you need to install NetBeans, simply run the file you just downloaded and follow the installation instructions.

4d0c4e0d99ad59b1ed1af2fc7c371d18

Providing you selected to create a desktop shortcut during the installation you will get a similar looking icon. Click it to run NetBeans.

Downloading the Java3D Libraries

Download Java3D
https://java3d.java.net/binary-builds.html

These are the libraries which will need to be imported into your IDE to create the Java3D programs. The download link above will automatically start the download for the zipped folder.

Extracting the libraries

Extracting the libraries requires an unzipping tool, Windows comes with a zipping/unzipping tool already installed so there should be no problem. Locate the zipped folder which you have just downloaded.

bdf855427499079c479246713b4e8f38

It should look like the image above. Now, to extract the contents of this zipped folder you need to right click it and unzip/extract it. This part will be different for people, depending on what unzipping software they are using. I am using WinRAR so, I will demonstrate this using WinRAR.

d6d9c1ed55262df0d5ad6e08b5070b3f

Click the extract button as shown above, this will create a standard folder in the same location and with the same name. Now you  need to locate that folder.

411231b3b36a05dff4c57368f4f22297

Open the folder and you will find a file structure as in the example below.

b99965d97d312866b882a185996287fb

You can almost ignore all of these files, except the j3d-jre zipped folder, this is another zipped folder which you will need to extract. Do the same as we have done previously and extract/unzip that zipped folder.

7cb99d4a6f4941024b10425005d5bc17

Open that folder, open the lib folder and finally open the ext folder. You will  then find a file structure as seen below.

6f565f381f484c64fe2ab3d3f37e0478

We are now done for this stage, you will need these three jar files later so it is recommended that you create a folder to hold them on your desktop or just remember where they are located.

Setups

Setting up Eclipse with Java3D

If you are using NetBeans you can skip this section.

Run the Eclipse application and you will be promoted to select a workspace. I setup a new folder on my Desktop called Java 3D Examples, you can do the same but feel free to call the folder whatever you like.

55ff301fb775f369d2311cb2dccfbb9b

Right click in the “Project Explorer” and click “New”, then “Project”.

60e74d723446e4d91028f0f5c1f0ca35

You will then be promoted with the project creation wizard, simply select “Java Project” and then “Next”.

0fb42dfb9c6b0f3b7ec560993307c6ab

Enter a project name, this is your choice. Finally, select the correct JRE version. If you do not have the JRE installed you can download it from here: http://www.oracle.com/.

6fdaecb6f918b751a1ff4b39947f9267

Now you should have a fresh new project located in your project explorer. Right click the project and select the properties button. A window should appear as shown below.

d960cd9d3a94e9a07e825a426f427834

On the left side of the window, click on the “Java Build Path”. Then click on “Libraries” in the main body of the window. Your screen should look like mines does below.

d31a741bbf6091a34b8a58713becf55b

Now click the “Add External JARs…” button on the right side of the window. This will open a new file explorer window, locate the three files which we found before after extracting the Java3D package.

c9218ad4663c7e60743f6b77d66a6bc8

Highlight all of the files by either shift-clicking on them all or dragging the cursor to select them all. Then click the “Open” button, in the bottom right of the window.

You will now have a window looking similar to mine below.

aa57211110f247a1e819c1dabe17fd46

We’re almost done. Finally we need to link the source for each of the JAR files. Find you way back to the Java3D file which you extracted before. This time instead of opening the lib folder, you want to open the bin folder. You will find the file shown below.

a7f22fd78588166905b331b3edf3bdea

Copy this file to a folder which you can easily access, make sure to call this new folder “bin3d”. Then go back into Eclipse.

You need to click the “Source” button in the window as shown below. Then click onto the “Link Source…” button on the right of the window.

aea52c92703624f51a5e59e800ebcb7a

A window will open as shown below, click the “Browse…” button and a new window will open showing your file system.

93e8c8c59645cc6fc2bec89f614750ab

You now need to locate the “bin3d” folder which you recently created. Once you have found it, select it and press the “OK” button.

7f471b577ee8b5b90dbd572cab40981d

Once you have done that you can now press the “Finish” button in that current window.

You will now need to hit the “Apply” button in the bottom right of the screen.

Go back into the “Libraries” tab in the current window, then click the drop down arrow next to each of the .jar files that we previously imported.

58c3e88922a5e19425fe6772035279eb

Each one of these .jar files has a “Native library location”, this is current set to none. Click on the “Native library location” for the “j3dcore.jar”, then press the “Edit…” button over to the right of the screen. Refer to the below image.

a87380fe06ff75337f47479b9c25ace3

You will be greeted by the below window, click on the “Workspace…” button.

124c23979fd5b650defd0d7312c4a97a

You will then find the below window, this window shows all of your current Eclipse projects in the current workspace. Locate the current project that you are working in and expand it by clicking the little arrow. Locate the “bin3d” folder and select it. Then hit the “OK” button.

a9c66b79f9f65825928bd1781699bf63

Click “OK” again on the screen as shown below, ensure that the “Location path” is similar to mine.

6b430b807a6a5cbddc2b6ba55a3999b1

You will be taken back to the main properties window. It should now look similar to mine, as shown in the image below.

d25c5fa1bb5010b2fc2bc3fd8a149f2b

You will now need to do this for the other two .jar files. Repeat exactly what has been done above for the “j3dcore.jar” file.

You will now need to hit the “Apply” button in the bottom right of the screen.

You can now press the “OK” button to close the properties window.

We now need to create a class and ensure that the files were imported correctly. Open your current project and right click on the “src” package folder. Click on “New” and then click on “Class”.

ac67a49523073299cacafa909e24808d

Make sure to name the class “HelloWorld” (class names cannot have spaces). Then press Finish.

3fdd5eea2cb46aed917c7597625331b6

Open up the new empty class file. We can now test whether or not you imported the files correctly. Copy the code below.

7bef48e91960935c24619bd082ed33e2

Hit the run button in the top toolbar in Eclipse, the button looks like the button shown below.

2ca72630a5e71d49481e44808fdf5e74If the code compiled correctly, without any errors you will get a Java 3D application open which looks like the image below.

cb2df7ea45e2f96b468eb626a27e37be

If everything worked correctly for you then congratulations! You can now close this tutorial and the remaining part of this tutorial is the same thing except in NetBeans. You should continue on to the next tutorial. For each project you make you will need to set up Eclipse in the same way.

Setting up NetBeans with Java 3D

Now you need to open NetBeans and create a new project. To create a new project right click in the project tab on the left of the screen, then press “New Project…”.

c7185af91416a01b9a69ad545fd6d0b2

In the window which has just opened, press “Java” and then “Java Application”. You can then hit the “Next >” button.

78a8eca2df73f99f8a375fb07ecef1ef

Then, select a name for your project. I called mine “Hello 3D”, select a location and ensure you uncheck the “Create Main Class” box.

b71208154fa7e6c1267075b63429cbbb

DOUBLE CHECK: Ensure you have the “Create Main Class” checkbox NOT checked.

999d42da9454a38ab866dffc375e8bba

You can now press the “Finish” button, your new project has been created and should be displayed like in the image below.

98941ad30c7f07545a8607c56d84a008

Right click the libraries folder and click “Add JAR/Folder…”. A window will then open showing your file explorer. Locate the three JAR files that we extracted before, like in the image below.

6e80a4b20f47634e9f9432b2ac693d83

Highlight the three files by either shift-clicking on all of them or by dragging your mouse to select all of them. Then click the “Open” button.

Your libraries folder should look like mines, as shown in the image below.

0d72856b1a9a3467677e6291132a5767

We’re almost done. Finally we need to link the source for each of the JAR files. Find you way back to the Java3D file which you extracted before. This time instead of opening the lib folder, you want to open the bin folder. You will find the file shown below.

a7f22fd78588166905b331b3edf3bdea

We need to put this into the root folder of your NetBeans project. Locate your NetBeans project. The file structure should look similar to the image below.

8d10460a7a26254bc0d9435043f92386

Drag the “j3dcore-ogl.dll” file into that folder. You can then go back into NetBeans.

Now we need to create a new class. In your project click the small “+” next to “Source Packages” and it should expand. Right click on “” and press “New” and then “Java Class…”.

3ec02b9271ac4825ab624ad279cfe8ff

Name the class “HelloWorld” (class names cannot have spaces) then press the “Finish” button.

0e663d80b87c29d22249979a4bdfbf74

Here is the code for a basic Java 3D program to test that all of the files have been imported correctly.

c8de7c7061fbcfbb70f68b698b498415

Now press the run button at the top of the screen to run the program.

b3f5618cb5e22dd18d6d21cd63a2eac8

If the program compiled successfully, the below image should be the result.

2fa5fc0660719017a48f8d940b6edc20

If everything worked correctly for you then congratulations! You are now done and can continue on with the programming tutorials. For each project you make you will need to set up NetBeans in the same way.

Advertisements

5 thoughts on “Getting Started: Java 3D API Installation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s