How to install jar library? - java

I've downloaded the ANTLR Java runtime libraries. It's a jar file. It contains "org.antlr.runtime". Where do I put it so that the Java compiler can find it? Do I need to extract it? I'm using NetBeans (for now), if relevant.

Assuming you can find your jdk folder, You can move the .jar file into the jdk\jre\lib\ext folder, where other .jar files are placed. After doing so, NetBeans should be able to run files with access to the library

For NetBeans you go to your Projects Tab and then right-click on the project you want the library added to then click Properties. Go to the Libraries bullet then on the right side click on Add JAR/Folder. No need to extract it. All you have to do is right click in the editor window and click Fix Imports.
For use outside of NetBeans you have to add it to your Java classpath.

For java command line you need to add it to your class path however in Netbeans you just need to add it as a library. It can be anywhere. Google to find out how to do these things.
In fact in netbeans, you can just say you need this in your maven project and it will do the download of the jar and its source/documentation as required.

Related

Visual studio code cannot find java libraries

I've setup a Java project in Visual Studio Code. I installed previously a few java extensions :
and I can create a program that does Hello World.
In a folder called lib inside the project folder, I copied some jars (lwjgl3) and, although are shown by intellisense when I try to import them, I have an error that says it cannot find the package :
Anything I missed ?
You need to add the jar to your classpath. The classpath is something used by java to find the libraries your program uses. Java looks in each folder/jar archive to find the class files, because it would be slow if it searched every directory on your computer. See this question: What is a classpath and how do I set it?
Add a reference to the package in the following way.
Click the plus sign to the right of Referenced Libraries under the JAVA PROJECTS panel
Select the .jar file in the pop-up window.

What is the "right" way to add libraries on Netbeans?

I'm a using Netbeans 8.1 to code in Java, when I want to add an external library (such as XStream, JDateChooser, etc) I find the .jar online and I add it to my project through the right clicking in Libraries --> add JAR/Folder.
After this I write my code and everything works fine until I finish my project and I want to export it into a .jar with Clean and Build
I think this maybe because I give an absolute path to the libaray instead of a relative one but I'm not sure.
PS: The library that I'm having trouble with is XStream 1.4.7
All the libraries included should pack in a jar file after build. The simplest approach is to click right on your project, select Properties and The project properties. In the new window opened find Categories and Libraries. The in the right side you may see the button Add library/JAR. Probably it's the same way.
Also you can create a Maven project and import all the libraries through dependencies.

How to change Java Build Path for Android in Eclipse?

I'm having a build problem with a specific file that I'm not being able to change the path on my Android project. Here is a picture of the problem:
How do I change this Path: /Users/apple/Downloads/dolphin_player/p/libs shown in the picture?
Change it from the libraries tab. You cannot do it from the order and export tab.
On the libraries tab, remove or edit it.
Its very simple, just follow these steps,
Right click on your project, select properties,
From the dialogbox select "Java Compiler" in left part, see image
It depends on the which version of java you are using.Just go to library tab and do following.
If you are using the 1.6 version of java the whenever you want to add any third party jar files you have to add it by adding external jar file in the library option.
If you are using the 1.7 version of java then you have to make a folder called libs and put the all the external jar files in this folder. It will automatically add the files to yous build path and add it in "Android Dependencies".

Java API in eclipse

Im new to eclipse , can anybody tell me how to use an JAVA API in eclipse. or share any sample Java API.
Yes, how to use JavaDoc file in eclipse.
Yes, how to use JavaDoc file in eclipse.
You can download the Javadoc jar file from the respective project and include it in your build path
Eclipse==> project-->properties-->Java Build Path-->click on the jar file--> edit JavaDoc
Point it to the API URL location/Downloaded Jar file,
Typically, shift + F2 opens the API when the class is focussed upon
Do you mean: how to use a third-party Java library in your Java project in Eclipse?
Right-click your project in the Package Explorer and choose Properties. Go to "Java Build Path". Click "Add JARs" or "Add External JARs" to add the JAR file(s) of the library to your project.
"Add JARs" is for adding JAR files that are in your project directory. "Add External JARs" is for adding JAR files that are not in your project.
Note that the Eclipse help (Help / Help Contents) contains a lot of information, including information on how to work with Java projects in Eclipse and how to add libraries to your Java project.
Here are some nice Eclipse video tutorials . The version of Eclipse is dated ( 3.1 ), but the concepts are still there.
I'm not clear exactly what you're after, but if you create a new Java project, you will have access to the JRE system library's contents as a classpath container.
File->New->Java Project, enter project name, select OK.
You'll then be able to create new classes and access the Java classes.
If you want to reference another jar containing the "API", you can add it to the project's build path.
Say the jar is in the "lib" folder of your project, open the project properties (alt+enter), the Select Java Build Path, then the Libraries tab, select Add JARs..., then browse to the lib folder and select the jar you want to add and select OK.
To attach sources and javadoc to the jar, you can expand the selector in the Libraries tab, click on Source attachment and Edit... and browse to the location of the sources jar/zip, repeat for the Javadoc. The screenshot below shows you the Source attachment option for rt.jar
(source: vogella.de)
and ok back to the workbench.
You should now see that the jar is included on the project's path (the jar has a little overlaid icon on it).
If this is not what you're after, can you rephrase the question?
what you need to do is to hover mouse over some in-built method or class that are using in your program. Hold ctrl on your keyboard and click. Then eclipse asks you to attach source. click on 'attach source', browse for src.zip file after choosing 'EXTRENAL' file. or instead give path for extracted src folder under same ie external file attachment. Next time you hover over an in-built class or method it shows a small description. To view entire javadoc for same, keep holding ctrl and click on it. It worked for me.

How to import java classes from other projects in NetBeans 6.8?

I have just started playing with Java, and I really like the language. I am using the NetBeans IDE, and I find one odd oversight. I can create a new class in a project, but NetBeans doesn't appear to support any way to import an existing class into a project.
I manage to get it done by going to some other project where the desired class already occurs, and then I copy/paste it into the source code folder of the new project, then change the package name at the top of the pasted file to match the package name of the new project.
Is there a nice direct way to do this from the NetBeans interface?
Thanks for any help on this.
In the Projects window you can expand the project that you are working on. Right Click on Libraries and select Add Project.... You will get a dialog allowing you to select another Netbeans Project with the Java classes that you wish to use.
You have to just make the .jar file of that/those java files which you want to use in another project.
right click on file->export->java->.jar then finish.
Now you can use these jar into your another project.
When you build the java project in netbeans it creates a jar file on the dist folder in the current project directory.
You can use this jar file for the other project as a package by adding this as ADD jar in the next project.I have tried this ,i am using my old project jar file for new project development.
Use the 'Clean and build' your project option from the netbeans application, that creates the 'dist' folder which you are looking for (and obviously can't find because you havn't cleaned&buld)
The netbeans itself creates .jar files and you can add the jar file to the current project you are working on.

Categories