Ok, I am trying to be a hero (helping my kid) and I am now looking like an idiot...
I am helping her move a working command prompt Java program into netbeans IDE so she can use the debugger to do the more complex things in the assignment. I am running into a problem importing a class file she is given that she must use.
Within netbeans, I've imported things I wrote before. This is the first time I try to use a class I didn't write but just given to me (in a file called Input.class). Under command prompt, I write a program with Input.something() and it works. It compiles without an import command in the code, I just put the Input.class in the same directory and it compiles and runs OK calling the methods in Input.class.
So, with a working simple test program, I am ready and moving onto netbeans. But I am having problem incorporating this given Input.class file into a netbean project.
The lines of test codes to test it is simple:
...
int thisInteger = Input.getInt("Enter the number");
System.out.println(thisInteger);
...
I found no way to directly use a .class file inside netbeans. The libraries and other tools seem to demand a .jar file. So I begun test with first convert the .class into .jar, then add JAR into the library and test the code with a simple "Hello World" program.
In command prompt:
- I use "jar cvf Input.jar Input.class" That created the Input.jar with the given Input.class file.
Inside netbean:
- I created a "Hello World" project, and the System.out.println("Hello world") works.
- With this working project, I add the Input.jar to the library
- I go into the project's Libraries folder and right click to Add JAR/Folder
- I selected the Input.jar and added it.
- In netbean Project window, I can see the Libraries folder now has Input.jar
- In netbean Navigator window, I can navigate to Libraries folder and see it.
Libraries
Input.jar
<default package>
Input.class
<META-INF>
MANIFEST.MF
- So, it looks like Input.jar is added and it has Input.class which has Input.getInt() method.
- BUT... adding a line to use Input.getInt(), Input.getInt() is undefined.
- So, simple I thought, I need to add the import command to import this JAR package into my "Hello World" project.
"import Input.*;" doesn't work. I don't have a package call Input. (but Input.jar is in the library).
I am missing something. Import expects a package name, but this .class file is given to me so I don't know what package if any this Input class is under.
With other JARs, I put it into the main library and they work. So, I directly putting Input.jar in the ...jre\lib\ext\ folder to try but that doesn't work either. With the other JARs I tried before, I know the package name and I know how the how "import packageName.*" should look. This one, I just can't get the imported class methods to be recognized.
What am I doing wrong here? Is there another way to import a .class directly?
Thanks
Rick