• Post Reply Bookmark Topic Watch Topic
  • New Topic

making personal libraries  RSS feed

 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make my own personal library of classes. I am using netbeans as the ide and have the latest version of Java installed on my mac.

I have looked a lot of tutorials but I can not figure the logic on how make this work.

This is the snippet of the code in my project  

//Lay out the panel.
        SpringUtilities.makeCompactGrid(p,
                                        numPairs, 2, //rows, cols
                                        6, 6,        //initX, initY
                                        6, 6);       //xPad, yPad

The line of code SpringUtilites has an error. I am sure it is because it can not find the SpringUtilities. I have a folder called SpringUtilities in the same folder as my project. That folder has a springutilities.jar file which contains the make.CompactGrid class. I have tried to use an import but I just can't get straight in my head as to how this should be done. It seems simple but I'm just not able to get it so I need help.

How should the library be set up?
What names should the library etc be called?
Do I need to worry about the upper/lower case of the names?
What do I need to call the package that the classes are stored in? Dose it matter?
What is CLASSPATH found in netBeans preferences and should I be using this?

Thanks
Roger
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
springutilities.jar file which contains the make.CompactGrid class


Is the springutilities.jar file on the classpath for the compiler and later  for the java command?

According to your source, the SpringUtilities.class file should be in the jarfile. I don't know what make.CompactGrid class is.  I see a makeCompactGrid method that looks like it is a static method in the SpringUtilities class


Do I need to worry about the upper/lower case of the names?

Yes for the class and package names and the path to the folder with the class file.  The name of the jar file depends on the OS's requirements.


What do I need to call the package that the classes are stored in? 

The package name should be related to the project the classes are in. 

Dose it matter?

Yes all your library classes should be in packages.
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure as I don't totally understand?

This is my file structure showing where everything is stores. I an almost sure that my naming is incorrect
Screen-Shot-2016-08-01-at-5.21.59-PM.png
[Thumbnail for Screen-Shot-2016-08-01-at-5.21.59-PM.png]
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to post the contents of the command line used with the javac command showing the classpath it used.
Also show the source for the program being compiled and the source for the files in the jar file and the contents of the jar file.  And the jar file's location.
We need to see the package statement for the class in the jar, the import statement of the file being compiled and the paths to the class file in the jar file.

For the javac command to find a class used in a source file, there must be an import statement in the source (if the class is in a package) and the classpath must point to where the package/class file is located.
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the 2 files. I have not figured out how to get the CLASSPATH



 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that's a start showing the package statements.
Now you need to show:
the import statement
The contents of the jarfile showing the location of the class files
The location of the jar file.
The classpath value used with the javac command
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Ok, that's a start showing the package statements.
Now you need to show:
the import statement
I thought I was showing the import statements. My project is the first file and it has my import statements. At times I have used a import java.springutilities.*;


The contents of the jarfile showing the location of the class files
The jar file is the last listing package springutilities. Is that what you mean?

The location of the jar file.
The location of the jar file is shown in the screen shot?


The classpath value used with the javac command
I don't understand how to do this.



I appreciate your help and patience as you can tell I am pretty much a greenhorn...But I am determined I am going to get this.

Roger
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath value used with the javac command
I don't understand how to do this.

The classpath (-cp) option has the path to the jarfile and other classes.  The . is for the current directory.  For example:
javac -cp folder1/folder2/TheJarFile.jar;.  TheClassToStart

I thought I was showing the import statements. My project is the first file and it has my import statements. At times I have used a import java.springutilities.*;

Where is the import for the classes in your package?

A suggestion:  Make a small, simple project for learning how to use packages, import and jarfile files.   The code you posted is way to big to work with for testing.
No source file should have more than 10 lines.
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm I appreciate your help. I think I must have slept through some of the classes I viewed. I think I will go back and do some review and then try again. At least I should be able to talk the same language.

Thanks
Roger
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another suggestion, setup a small project with several  small "HelloWorld" type classes (have methods that print a message), each in their own package and own folder.  Use import statements to access them from the class with the main().
Use the javac command with the -cp option to set the classpath to access each package.

Later put all the  classes (except the one with the main()) in a jarfile and
use javac -cp TheJarFile.jar ... to compile and
java -cp TheJarFile.jar;. ... to execute
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good ideal

Your post seem to show using the command line to run and work with Java?

I am using netbeans which dose this make a difference?

Roger
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using netbeans which dose this make a difference? 

yes, a huge difference.  I suggest that you do the simple project from the commandline to get an understanding of what is required.  The NB IDE will do all that for you if you can figure out how to configure it.

My IDE is an enhanced Editor that uses commandlines with simple replacements.  I've used it for years, from long before IDEs like NB came out.  Most of the IDEs are so slow loading and frustrating to configure that I have never bothered learning how to use them.  Although I do use Eclipse for Android and Visual Studio for C++ work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!