Skip to main content
gamedev.net
🔒 Locked

[java] Eclipse newbie question

Started by Axiverse 2 replies 650+ views
Original Post
Axiverse
Axiverse
I have a .class file which i want to use in my project. I drag it in, but it doesn't appear in my package explorer? How do you use .class files?
StarikKalachnikov
StarikKalachnikov
Eclipse's package explorer probably has some sort of filter for .java files, which kinda makes sense, because packages only contain .java source files. When you build all your packages then they become .class files.

Do you care to explain why you want to use .class files? Java libraries work through .jar files which you can then add to your project and use as you like.

Next time I give my advice, I'll buy some bubblegum so I won't your kick ass!
OrangyTang
OrangyTang
If possible, use external libraries in .jar form. But if you can't do that, IIRC you should be able to do it like this:

- right click the project
- select 'properties'
- click the 'libraries' tab
- click 'add class folder' and point it at a directory containing the .class files. Remember you still have to use the package directory structure in there too.
polly
polly
Better to get into the habit of using jar files. To create your jar file do the following:

Quote:

$jar -cvf MyJarName.jar *


This will place all of the files (indicated by the wildcard *) underneath the current directory into your jar file and name if MyJarName.jar. You'll need to do this at the top of your package structure.

Free Tip 1: When you want to see whats inside a jar file unzip it with the following command:
Quote:

$jar -xvf MyJarName.jar

Although you can navigate through the contents of a jar file inside of Eclipse, which is probably quicker.

Free Tip 2: Create a "lib" subdirectory in your Eclipse project and place any .jar files you use in there. Don't forget to add your jar to your build path by doing Project->Properties->Libraries->Add JARs.

Jon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.