How to import libraries in Netbeans? - java

I am working on a Java program, where it will print the stored string in backwards. And I would like to use the ArrayUtils method. So, in order to do that, I have to import org.apache.commons.lang.ArrayUtils; (commons-lang-2.6.jar), which I dont have. And I would like to download it and add it to the library. Once I am in the commons.apache.org page and look for commons-lang-2.6.jar, there are actually 2 sections : Binaries, and Source. Which one should I download and how do I add the library?

"how do I add the library?"
To add a new Library to NetBeans,
do the following (after downloading and extracting the library you need)
If you click Tools -> Library a popup will come up.
There you can add a new library. Click on New Library and give a name the new Library.
Import a library from the ClassPath tab - click Add Jar/Folder, locate and select.
If you want to can also add the javadoc from the JavaDoc tab. You would add the file from the library file you downloaded, called javadoc. This will allow for the javadocs to be seen while editing your code.
Also you can add the sources file form the Sources tab. Import the file named sources
Then right-click on the Libraries folder icon in your project and Add Library
Another option is just add the .jar.
Right-click on the Libraries folder icon in your project and click Add Jar
Locate the .jar file and add it.

the next link contains a jar file which you can import to your project (into libraries):
http://www.java2s.com/Code/JarDownload/apache-commons/apache-commons-lang.jar.zip
basically, the binaries files are compiled code and that is what you want.

Related

How do I use classes from an imported library in netbeans (java)

This must be the simplest thing. I have been trying to do this for hours. I know how to import libraries into netbeans but how do I use classes in these libraries using imports? I have been trying unsuccessfully for hours to use the javacv library on 64bit linux and when I try to import the necessary files from the library netbeans tells me the package does not exist. I want to access a java file example.java inside com.googlecode.javacv.cpp.linux-x86_64 which is inside opencv-2.4.8-linux-x86_64.jar. How do I actually import this so I can do the following: example obj = new example?
Also, in almost every reference to javacv I see this import com.googlecode.javacv.CanvasFrame; but nowhere have I actually seen this in any of the files readily available by google. What's the deal?
Please give this a try, I will be as specific as possible:
Copy the library folder you want to use
Paste it in the "src" folder of your project folder
Once you completed the above two tasks, you can import different classes from the library using the following code:
import nameOfLibraryFolder.*;
The above code will import all the classes from within the library. Replace "nameOfLibraryFolder" with the name of the library folder, to be more specific, the folder that contains all the classes of the library, to be even more specific, the folder that you placed in your project's subfolder called "src".
In order to import a specific class from the library, you need to replace the * symbol with the class name.
For example:
import nameOfLibraryFolder.className;
but if the class is in a subfolder, then:
import nameOfLibraryFolder.subFolderName.className;
I hope this is specific enough, and I hope it helps.
In netbeans, it is rather easy to iomport a external jar and utilize it.
First you need to add jar file in project tab by right clicking on the library node.
Then, in this project, just import the.name in your java file.
This should work, I have used Netbeans for three years
You many need to do one of the following option.
Add an new Library to NetBeans, then add it to you project
If you Tools -> Library a popup will come up.
There you can add a new library. Click on New Library and name the new Library.
Import a library from the ClassPath tab Add Jar/Folder
If you want to can also add the javadoc from the JavaDoc tab. You would add the file from the library file you downloaded, called javadoc. This will allow for the javadocs to be seen while editing your code.
Also you can add the sources file form the Sources tab. Import the file named sources
Then click on the Libraries folder icon in your project and Add Library
Another option is just add the .jar.
Right-click on the Libraries folder icon in your project and click Add Jar
Locate the .jar file and add it.
As long as you have:
package MyProject;
At the top of your project Java wont recognize it.
* It seems to be like some sort of sandboxing affect.
* To use your classes you have to open the directory you
* Saved the project to and Copy/Paste the library to the source file.
* I also found that simply deleting the named package works as well.
* But now you're no longer linked to that package. -shrugs-

How to import src project in eclipse

So I am working on a java project that requires me to analyze the Dijkstra and Bellman Ford algorithms by running time.
Now I am trying to write my collected data to an xls or xlsx file. I have found the Apache POI: http://poi.apache.org/download.html#POI-3.10-beta2 which will help me do that.
My only issue is that I'm having trouble adding the source to my existing project to use. Apache POI comes as a src folder. Dragging and dropping the folder into eclipse adds the files but the packages aren't right.
For example, in one of the java files the package is declared as:
package org.apache.poi.hpsf.examples;
But when dragged into eclipse the package becomes examples.src.org.apache.poi.hpsf.examples... This causes eclipse to throw the "The declared package "org.apache.poi.hpsf.examples" does not match the expected package "examples.src.org.apache.poi.hpsf.examples"
Now I could simply move this package to the right folder but there are dozens of packages with this same problem?
How would I properly add these files to eclipse so I could use them?
I would write to CSV then import the CSV to Excel, unless there's a compelling reason specifically for using Excel. The benefits of this are:
No need for extra libraries.
You can open the file in other things (emacs, load into R to draw graphs).
If you really just want to use POI, the thing to do is download the JAR file, go to Options > Properties > Build Path > Libraries > Add JARs and then select the jar. (You should see a dialog like this.)
Right click on the project name -> Properties -> Java Build Path and on the the source tab, select the examples/src dir.
BUT, if I correctly understood the problem, you want to use the POI library, so in that case get a jar version of it, and then right click on the project name -> Properties -> Java Build Path and on the the libraries tab, select the location of the jar file.
This way, you can write your own java classes and import the POI library into your project.
Try the File menu, then select Import, then expand General, then "Existing Projects into Workspace". You will have the option of whether or not to create a new copy of the whole directory in your workspace directory as well.

how to import a java class by a jar file

I had a problem when importing org.slf4j.Logger and org.slf4j.LoggerFactory, how to download these two classes and if it is by the mean of a jar file, how to import from it.
To be able import any classes into your project, such classes should be added to the classpath of your application.
Usually you won't need to extract classes from library, so in your case you need to add slf4j-api-1.7.5.jar from slf4j-1.7.5.zip which accessible here: http://www.slf4j.org/download.html
Here you can find example how to add library for eclipse project: http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
If you do have the corresponding Jar file, you just have to add it to your project. If you are using Eclipse IDE, you can click on "Project" menu, "Properties", "Java Build Path", "Add External Jars..." and then a file chooser will appear. Choose the location of your Jar file and open it. Here you go. If you are using another IDE, just specify it, so we can further help you with respect to your IDE.

Where I could find the Import file in eclipse

I just want to know where does Eclipse store an import file like
import com.codecarpet.fbconnect.FBRequest.
Eclipse doesn't store the imports separately. You can browse the packages using Package Explorer window (mostly found at the left side of window).
Eclipse doesnt store anything for every import. Once you keep adding libraries to your project build path there is a .classpath file that is updated. It contains the list of all the libraries that you project depends on.
The .classpath file looks something like this:
Hover your mouse over FBRequest in the import statement, hold ctrl, a hand appears, click on it.
In package (or project) explorer, the view normally to the left click the two arrow symbol link with editor.
Click on the editor where your class file is, the editor won't look like normal JAVA.
Now you are in the jar file where the class file of the import statement is
Browse up In package (or project) explorer to you find the jar file and right click for properties. There you have a field location and there is were the file is on the file system
Eclipse does not store anything. You tell to Eclipse where to find referenced libraries. Please open project properties (right click on project + properties) and select "Java Build Path" from the list at left, then choose "Libraries" tab
That's plain Java. Eclipse doesn't store anything, you have to put the containing library in your classpath. You can edit your buildpath by right-clicking your project in eclipse --> build path --> edit build path. You can add the needed class-files (or libraries) here.

How to import zip file in netbeans project

when I was trying import a zip file in my netbeans project, I get a error in this line
import jericho-html-3.1.src.java.net.htmlparser.jericho.*;
even though I added the zip file Libraries folder.
You probably want to add library to your project so you could call it in your code.
From the line import jericho-html-3.1.src.java.net.htmlparser.jericho.*; I assume that you try to add source code to the project. This will not work.
You need to add a library library and not source code. The library file has .jar extension.
When you download a zip file from http://sourceforge.net/projects/jerichohtml/files/jericho-html/3.1/ The library is in /jericho-html-3.1/dist/ folder of the zip.
For library usage take a look on Sample Programs.
In the Projects window right-click on the name of the project that lacks library -> Properties -> The Project Properties window opens. In Categories tree select "Libraries" node -> On the right side of the Project Properties window press button "Add JAR/Folder" -> Select jars you need.
You also can see MockerTim's short Video How-To.

Categories

Resources