Netbeans and class files

I am trying to use a Java API for an off the shelf piece of vendor software.

The files included in this JAVA API are a bunch of compiled  *.Class  files.  I am having a hard time figuring out how to import these into my project.  For other API's I just import their Jar files and I'm good to go.  Not sure how to import the class files in so I can use them.  I think you have to put them in a package....I don't know.  Can't seem to figure it out.

How can I include and use these compiled *.Class files??

Thanks in advance experts

gusseology
gusseologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
you will have to make the package according to how they've been compiled
0
gusseologyAuthor Commented:
Hmmm.  I'm still kinda lost.

I mean, I have 10 or so .Class files.  I want access to them all.  It makes sense that they need to be in a package.  So how do I create the package accoding to how they've been compiled?  I don't know how they were compiled or anything about them other than the methods available to me.

I tried selecting them all and creating a zip and renaming to a jar, then importing that.  But it didn't work.  It put them in <default package> and I wasn't able to access them.

Sorry for my lack of knowledge.  I'm a newbie to Netbeans and Java.  Could you provide some more detailed guidance??

vr,

gusseology
0
CEHJCommented:
I don't use Netbeans, but you could try 'adding them to the project' or importing them or some such
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

gusseologyAuthor Commented:
yea, that's right where I'm getting tripped up.  You'd think it would be a simple task to add/import/etc. .class files to the project.  But it's not quite working out when I attempt it.

gusseology
0
CEHJCommented:
If you open the class file in a binary editor, the first readable characters you see will show you the package
0
objectsCommented:
The class files should already be in the required directory structure (matching the package hierarchy) in the api distribution.
You need to add the base *directory* of the class hierarchy to your project.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
I think there are two ways to go about this in NetBeans 1st one Make sure the Package structure of the class files is correct (hierarchy) and then do this

Right click on Source Packages folder of your Project create the same structure of folders and put those class  files in it.

else

Right click on Libraries folder of you project and select the Add Folder/Jar option and add the folder(top folder if in package) conatining the classes.

the only other option left which will surely work is to create a jar file and add it in the liraries folder as per the 2nd step metioned above.

Thank You.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
Try to JAR the API's class-files from their root-directory and simply add the JAR to the project's build-path.

http://java.sun.com/docs/books/tutorial/deployment/jar
0
riaancorneliusCommented:
>> Try to JAR the API's class-files from their root-directory and simply add the JAR to the project's build-path.
>> http://java.sun.com/docs/books/tutorial/deployment/jar

That's correct. Then when you have a jar file, you can either put that jar somewhere in your classpath ( like: java/jdk/jre/lib/ext ) But I don't like this method. What I'd rather do is either mount the jar in netbeans (if it's version 3.5 or 3.6), or otherwise include it in your projects libraries for later versions...
0
Mayank SAssociate Director - Product EngineeringCommented:
>> But I don't like this method.

Its reusable for all IDEs ;-)
0
riaancorneliusCommented:
Yes, But it can be quite difficult to debug if something goes wrong, and it's also shared by all java apps, so if somebody else overwrites a library with an earlier version, your app stops working....

If it's only for dev, I'd say sure, go for it. Just make sure that if you distribute it that you have a better way of doing it :)
0
Mayank SAssociate Director - Product EngineeringCommented:
>> But it can be quite difficult to debug if something goes wrong,

Well, then that can be said about all JAR files ;-)
0
CEHJCommented:
The issue really doesn't have much to do with jars. Once it's in the correct place (see how to find that place in my last comment) your can either incorporate it into a jar or not depending on your requirements
0
Mayank SAssociate Director - Product EngineeringCommented:
Yes, it was just another option to make it more redistributable.
0
gusseologyAuthor Commented:
Thanks for all the comments!  Sorry I didn't get back sooner.  

I actually tried (or at least think I tried) the options you outlined.  

I tried creating a jar by two different methods.  One was zipping the files together and renaming it to a jar.  THe other way I tried it was by using the jar.exe program and creating one.

So anyway, now I have a jar file created form the class files and then I attempt to import it in the same way I import any other JAVA API jar file (by right clicking on library, Add Jar..etc etc.).  That's where I get the problem.  With the other Java API's I have, when I add their Jar files, they get imported and are located in a package structure.  And referencing them is easy, i say import bleah.bleah.bleah.*

However, when I import the Jar I'm having problems with, I get a package called <default package> and under it are the class files.  And I can't seem to reference the package named <default package>.

gusseology
0
CEHJCommented:
Forget jars for the moment - they're not relevant. Did you follow the methodology i suggested (i suspect not)?
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Just try my suggestion and get back.

Thank You.
0
gusseologyAuthor Commented:
Oh, opening the binary file and finding the package location.  Sorry, haven't tried that.  I'll try it now.

The reason I shyed away from it is because it seems overkill.  There has got to be a way to simply import class files into a project in Netbeans and let your app use them.  I mean....they're class files!  You have to be able to reference them!  Right?  

It seems my original question should be readily available and easy to learn, but for some reason I can't simply import and use class files.

But thanks for the suggestion CEHJ!  Too complex or not, I'll give it a shot.  But I still think there has to be a more elegant and simple way to import and use class files

gusseology
0
CEHJCommented:
>>The class files should already be in the required directory structure (matching the package hierarchy)

>>Make sure the Package structure of the class files is correct (hierarchy)

You can't determine that without internal inspection once the class files have become disconnected from their original context, as seems to be the case here.
0
CEHJCommented:
>>There has got to be a way to simply import class files into a project

Well that's reasonable, but i haven't seen *much* helpfulness from IDEs with arbitrary imports
0
objectsCommented:
I doubt they are in the default package, and if they are then you can't reference them anyways.
Did you check how they were stored in the api distribution, that should give you the package hierarchy and allow you to add them all to your project by adding the top directory.
0
Mayank SAssociate Director - Product EngineeringCommented:
Are any 3rd party APIs distributed not as JARs/ Zips or something of the like? If you can find out the original distributable you would have something handy like that (check with your colleagues or see if it is a free download on the Net?).
0
CEHJCommented:
There's no need for all these enquiries - just look in the class file ;-)
0
Mayank SAssociate Director - Product EngineeringCommented:
That would be the faster way to make it work but I would prefer having it JARed as the better way to make it work in the long run.
0
CEHJCommented:
Yes but jarring it won't affect the problem - the package hierarchy will have to be discovered anyway
0
gusseologyAuthor Commented:
I got it guys...thanks for the comments, I'll distribute points later.  I only have a minute, so I wanted to post the solution now and I'll figure out how to distirbute the points fairly later.

Here is what you do.  Go to the project.  Choose the sources section.  Right click and choose new and then choose java package.  Once that package is created (we'll call it packagename), it will be empty.  Go to that packagename's directory in widows explorer and drop all the class files off in that directory.  Build the project.

Then go to the libraries section, right click and choose add jar/folder.  add the folder containing those classes.

In the main.java you can put
import packagename.*;

And then you know have access to all the methods in all those .class files.  Your'e good to go at this point.

I will detail the steps tomorrow when I have more time, but that's pretty much it in a nutshell.

thanks for everyone's suggestions!

gusseology
0
Mayank SAssociate Director - Product EngineeringCommented:
>> the package hierarchy will have to be discovered anyway

Of course, JARring will have to be done from the root directory once it is known.
0
CEHJCommented:
>>Here is what you do. ..

If that's a success, it suggests that the classes were in the default package. Dropping them into any of *your* packages and then rebuilding should work too.
0
gusseologyAuthor Commented:
sorry for the delay in responding.

It was a success, I simply had to create a package, then drop the class files into that package (via windows explorer) and rebuild.  I was good to go.

Thanks for all the responses, I will distribute points.

gusseology
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Is that according to My first suggestion??
0
gusseologyAuthor Commented:
Looking back yea, it looks like it is much like your first suggestion.  But at the time, your first suggestion didn't make much sense to me.  Guess it's one of those things I had to have detailed directions or they didn't make sense.

thanks for all your help

gusseology
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.