Discussion:
How to include a .class file in my project
the_ether
2009-01-05 02:19:35 UTC
Permalink
I searched for ages but couldn't find an answer to what I thought would be a common issue.



I have a pre-compiled MathFP.class file that I want to include in my project. How do I do that? I tried simply copying it into my src directory but Netbeans didn't recognise it when I tried to add an import command in my code.



I only have the .class file, nothing else.



Thanks in advance for any assistance.
Nick Beare
2009-01-05 10:29:48 UTC
Permalink
Stick the MathFP.class file in a jar, then add a reference to that jar in
your project (My guess is that you extracted this from a jar in the first
place, in which case, refer to that jar).

Regards
Nick

-----Original Message-----
From: the_ether [mailto:***@yahoo.co.uk]
Sent: 05 January 2009 02:20
To: ***@netbeans.org
Subject: [nbusers] How to include a .class file in my project

I searched for ages but couldn't find an answer to what I thought would be a
common issue.



I have a pre-compiled MathFP.class file that I want to include in my
project. How do I do that? I tried simply copying it into my src directory
but Netbeans didn't recognise it when I tried to add an import command in my
code.



I only have the .class file, nothing else.



Thanks in advance for any assistance.
Wade Chandler
2009-01-05 15:35:17 UTC
Permalink
Too, if you don't want to JAR it you can point NB to a directory for a class path in libraries in the project properties.

For instance, say you have a folder my with child/sub folder somepackage and in somepackage is MathFP.class, so package my.somepackage and fully qualified class name my.somepackage.MathFP. You would put folder my in another folder called classes or something similar under your project folder unless you already have a similar library folder some where you can link to. Then you point the library to the classes folder. Then any simple .class files can be put there as long as you have the correct package structure. That is the important part...package structure and making sure you have the right parent directory selected. This also affects JARs, so you have to know the issues with classpaths and packages etc.

Wade

==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org



----- Original Message ----
Sent: Monday, January 5, 2009 5:29:48 AM
Subject: RE: [nbusers] How to include a .class file in my project
Stick the MathFP.class file in a jar, then add a reference to that jar in
your project (My guess is that you extracted this from a jar in the first
place, in which case, refer to that jar).
Regards
Nick
-----Original Message-----
Sent: 05 January 2009 02:20
Subject: [nbusers] How to include a .class file in my project
I searched for ages but couldn't find an answer to what I thought would be a
common issue.
I have a pre-compiled MathFP.class file that I want to include in my
project. How do I do that? I tried simply copying it into my src directory
but Netbeans didn't recognise it when I tried to add an import command in my
code.
I only have the .class file, nothing else.
Thanks in advance for any assistance.
the_ether
2009-01-05 14:11:25 UTC
Permalink
Thank you for your advice.



Silly question: how do I stick a class file into a jar file? Secondly, how do I reference it from within my project?



And no, the MathFP stuff came as is: .class files. It's a standard solution (apparently) for providing logarithm functionality to J2ME work, but comes as a set of .class files and no .jar files.
Nite
2009-01-05 14:53:51 UTC
Permalink
Right click on the "Libraries" folder of your project, "add class\jar".
the_ether
2009-01-05 15:20:12 UTC
Permalink
Post by Nite
Right click on the "Libraries" folder of your project, "add class\jar".
I'm using Netbeans 6.1. There is no libraries folder. Instead, I went to Tools / Libraries. There is no "add class\jar" option, only a "add jar/folder" one. Using that to select the folder in which the MathFP.class file is in doesn't work. I still get a package does not exist error with my line, "import net.jscience.math.MathFP;"
Nite
2009-01-05 15:34:37 UTC
Permalink
yes, its jar\folder, my mistake.

by the way, as someone already told you, all you have to do is pack that class into a jar, and import it with that "jar\folder" option.



to make the jar, this might work :create a new project choosing library template, put the class into a package and compile the project, you ll have a jar.
Thayer, Bill
2009-01-05 19:46:41 UTC
Permalink
Could you create a new NetBeans project with existing sources for your
MatFP stuff then add that project to the library of the project you are
working on?

-----Original Message-----
From: the_ether [mailto:***@yahoo.co.uk]
Sent: Monday, January 05, 2009 8:11 AM
To: ***@netbeans.org
Subject: [nbusers] How to include a .class file in my project

Thank you for your advice.



Silly question: how do I stick a class file into a jar file? Secondly,
how do I reference it from within my project?



And no, the MathFP stuff came as is: .class files. It's a standard
solution (apparently) for providing logarithm functionality to J2ME
work, but comes as a set of .class files and no .jar files.
the_ether
2009-01-05 16:10:15 UTC
Permalink
Post by Wade Chandler
Too, if you don't want to JAR it you can point NB to a directory for a class path in libraries in the project properties.
Thanks. This worked using "add folder" under the "libraries & resources" tab of my project and using the correct folder hierarchy as you described.



The fields of MathFP.class now appear in my project as a resource.
the_ether
2009-01-05 20:58:26 UTC
Permalink
Post by Thayer, Bill
Could you create a new NetBeans project with existing sources for your
MatFP stuff then add that project to the library of the project you are
working on?
Not sure I understand you. All I can say is that I managed to include the .class files into my project using the method previously described and so I am happy.
Continue reading on narkive:
Loading...