How do I import libraries in my java program without using an IDE like Netbeans? In Netbeans I do it this way:
How can I achieve the same thing by just using notepad++ or programmer's notepad. As much as possible I don't want to use Netbeans because it would be overkill since I'm only working on simple projects.
Right-click the Java project to which you want to add a library, and select Properties from the menu. Select Java Build Path, and click the Libraries tab. Click the Add Library button, and choose the appropriate Java EE Library. Click Next to view the library contents, and click Finish.
There are two main steps to accessing the functionality provided by an external library: Make sure the library is available to the Java compilation step—javac—and the execution step—java—via the classpath (either the -cp argument on the command line or the CLASSPATH environment variable).
Step 1: Right-click the project and select “Build Path » Add Libraries…”. Step 2: Dialog the window that pops up, select “User Library” and click the “Next” button. Step 3: Select the user libraries you want to add and click “Finish”.
One of the key features of Java is that it has a feature-rich and vast Core library. While the Standard Java library is powerful, you will need other Java libraries in professional Software Development.
javac -classpath external.jar myClass.java
EDIT:
If your main class is in a package
package com.mycompany; public class myClass { ... ...
then
you'll need
javac -classpath external.jar com/mycompany/myClass.java
and
to run
java -classpath external.jar com.mycompany.myClass
In addition to @StackOverflowException's post adding multiple files and locations is prefectly ok too...
javac -cp location1/;location2/;file1.jar;file2.jar fileToCompile
Notes::
-cp and -classpath are the same thing. If you're on Solaris (and some other UNIX flavors) change the ';' to ':'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With