How to use 3rd party packages in Java
Asked Answered
E

3

19

I'm developping my first Java application which actually needs a 3rd party package and now I'm lost as to how to actually use it. The packages I need are from VLCJ so that I can embed a media player in my GUI.

Usually, I can just import packages and classes, but is this possible with 3rd party packages? They have a .jar file to download at their website, are the packages stored in that? And if so, how do I go about using them in my own application?

Etana answered 16/6, 2011 at 15:11 Comment(0)
G
20

You just need the third party JAR to be on your project's classpath. What IDE are you using? In Eclipse you would do:

Go to Package Explorer window on the left. Select the Java project you are working on and right click. Click Properties. Then click Java Build Path. Click Add External Jars.

Or you could modify your system wide CLASSPATH to include the JAR. Or you can do it on the command line e.g.

java -classpath C:\java\thirdpartjars\thirdparty.jar MyProgram

(you can use the argument with javac too).

There are many ways to crack this nut.

Gasometer answered 16/6, 2011 at 15:15 Comment(2)
Great this works +1 and ill accept once able. I chose you because you gave me the procedure for adding it in Eclipse.Etana
this is soooo dumb. let me just import via an https link... or make it easy to do file imports like ./ im speaking of deno/node/npm of course. Kotlin is no better... made by the same IDE-industrial complex. great.Cristincristina
C
9

Yes, the JAR file you download is an archive (basically a .zip file) of compiled .class files which you can then import into your own application.

The only thing is you need to add the .jar file to your application's classpath for you to use it before you can import it.

I would suggest looking at a good Java book or tutorial (for example, the official Java tutorial) as this is all stuff that should be covered.

Cush answered 16/6, 2011 at 15:14 Comment(1)
Thanks, gave me the info I needed and the official tutorial is a nice refresher. +1Etana
M
6

You need to add the jar file to the search path of javac when you compile your project; and you need to make the jar available at runtime-- it needs to be in the classpath of the java process that runs your program.

If you are using an IDE, you usually update these paths in the project settings.

Matted answered 16/6, 2011 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.