Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import these Java classes I downloaded? [duplicate]

I'm a beginner in programming and I need to know how to import classes I got from the Internet to my text file. I downloaded JLayer for use in writing an MP3 player, but typing import javazoom.jl.player.Player; won't work, unlike the basic import statements like import javax.swing.JOptionPane;.

I read in some forums that I should move the JLayer library somewhere so that the import statement will work, but where exactly? My JLayer library is currently in my Downloads folder. What should I do?

like image 574
Jed Patrick Datu Avatar asked Nov 26 '25 16:11

Jed Patrick Datu


2 Answers

Put the JAR containing those classes in your CLASSPATH. You should know how to use the -classpath argument for both javac.exe and java.exe. Read the tools documentation.

like image 97
duffymo Avatar answered Nov 28 '25 05:11

duffymo


If you are using Eclipse or a similar IDE, select your project, then do:

File -> Properties -> Java Build Path -> Libraries (tab) -> Add External Jars

Use the finder to select your .jar file, and then Eclipse should do the rest for you.

Note: Eclipse will only reference the .jar file at its current location, it does not copy the .jar to your current project.


If you aren't using an IDE, duffymo's answer will work for you.

like image 30
syb0rg Avatar answered Nov 28 '25 05:11

syb0rg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!