0

After a long time, I've decided to start programming again for a bit of fun, I've created several programs using a text editor and the console, but I'm now trying to use netbeans and have a few issues

I created (with the text editor)a java class called Clavier which allows me to read from the keyboard, it has a couple of methods (one for strings, double, floats and int) and that's it. I've tested it and it runs fine.

Unfortunately I don't know how to import it with netbeans so that any program I decide to make can use it.

Can anyone help me please?

Thank you very much

RHarris
  • 23
  • 6

2 Answers2

0

You've got a couple of choices:

1) Literally move it into the directory of the project that you intend to use it in (to be honest since it is only one class this is easier)

2) Alternatively you can make a JAR containing it, so then you can import it into your project as a library.

To make a JAR follow the instructions here run the following from the command line from the directory containing your java file

javac <yourclassname>.java
jar cvf <name of jar> <yourclassname.class>

Now you can import this into a by right clicking in the project list and selecting add library

Good luck!

saml
  • 794
  • 1
  • 9
  • 20
  • Thank you, I've managed the first solution of creating an empty class and adding the source code to it and that works fine. I've created a JAR file with the commands you gave me and it worked fine but I can't seem to add it to my project. I can't find it in Add Library or in Add Jar/Folder – RHarris Mar 08 '16 at 10:29
  • Glad to hear it. Please accept the answer, if you found it useful :) – saml Mar 08 '16 at 10:30
0

If you place the .class/java file in the same location / workspace as where you are creating your other Java file in netbeans, then netbeans should do the rest of the work for you.

E.g say you're working in a directory called workspace and the class is called apple.java. Move apple into work space and you should be good to go.

Just make sure you instantiate the apple class if you want to use method from it, i.e

Apple appleObject = new Apple(arguments);
appleObject.methodNames();
Kieran Lavelle
  • 446
  • 1
  • 6
  • 22