简体   繁体   English

如何在Java中使用第三方软件包

[英]How to use 3rd party packages in Java

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. 我正在开发我的第一个Java应用程序,它实际上需要第三方软件包,现在我已经迷失了如何实际使用它。 The packages I need are from VLCJ so that I can embed a media player in my GUI. 我需要的软件包来自VLCJ,以便我可以在我的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? 他们有一个.jar文件可以在他们的网站上下载,那些包存储在那里? And if so, how do I go about using them in my own application? 如果是这样,我如何在我自己的应用程序中使用它们?

You just need the third party JAR to be on your project's classpath. 您只需要将第三方JAR放在项目的类路径中。 What IDE are you using? 你在用什么IDE? In Eclipse you would do: 在Eclipse中你会做:

Go to Package Explorer window on the left. 转到左侧的Package Explorer窗口。 Select the Java project you are working on and right click. 选择您正在处理的Java项目并右键单击。 Click Properties. 单击属性。 Then click Java Build Path. 然后单击Java Build Path。 Click Add External Jars. 单击“添加外部JAR”。

Or you could modify your system wide CLASSPATH to include the JAR. 或者,您可以修改系统范围的CLASSPATH以包含JAR。 Or you can do it on the command line eg 或者您可以在命令行上执行此操作,例如

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

(you can use the argument with javac too). (你也可以使用javac的参数)。

There are many ways to crack this nut. 破解这个坚果的方法有很多种。

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. 是的,您下载的JAR文件是已编译的.class文件的存档(基本上是.zip文件),您可以将其导入到您自己的应用程序中。

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. 唯一需要的是您需要将.jar文件添加到应用程序的类路径中,以便在导入之前使用它。

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. 我建议查看一本好的Java书籍或教程(例如, 官方Java教程 ),因为这是应该涵盖的所有内容。

You need to add the jar file to the search path of javac when you compile your project; 编译项目时,需要将jar文件添加到javac的搜索路径中; 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. 并且您需要在运行时使jar可用 - 它需要位于运行程序的java进程的类路径中。

If you are using an IDE, you usually update these paths in the project settings. 如果您使用的是IDE,则通常会在项目设置中更新这些路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM