How do you use a Java Library?

前端 未结 5 1934
逝去的感伤
逝去的感伤 2020-12-08 14:18

I\'m trying to use an open source java library to visualize nodes and edges in a graph, but I\'m completely lost.

I have a bunch of jar files in a folder. Clicking o

相关标签:
5条回答
  • 2020-12-08 14:18

    Have you included those libraries in your classpath?

    If you are using eclipse, you could

    Project - > properties -> Java build path ->addJar.

    And the Jar file should be placed in a directory inside your workspace (lib/ for example)

    If you have to take your project to another computer, you could take these steps

    1. Before doing anything, export your project (as a Jar file, for example).
    2. Save it into your favorite drive (cd / usb drive/ diskette/ tape).
    3. On "the other" computer, you can import this project into your workspace
    0 讨论(0)
  • 2020-12-08 14:18

    You use it by including it in the classpath of your java application, that way you can reference it from your code. Here is a starter document. The JDK 1.6 has some easier options (such as specifying multiple jar files as *.jar). It is definitely a little complicated, but it is very worth knowing.

    0 讨论(0)
  • 2020-12-08 14:22

    In Eclipse, you need to add libraries to the project build path.

    In general, you need to provide dependencies via the classpath mechanisms at compile time and runtime. The precise mechanisms vary, but, for example, if you used the javac compiler, you would provide your libraries on the command line:

    javac -classpath C:\dir\lib1.jar;C:\dir\lib2.jar foo/MyClass.java
    

    These dependencies would also be required to invoke the app:

    java -classpath C:\dir\lib1.jar;C:\dir\lib2.jar;. foo.MyClass
    

    This page gives some good info, though googling for the term "classpath" should provide alternative sources.

    0 讨论(0)
  • 2020-12-08 14:39

    I believe if you put the jars in your classpath, you can import and use classes just like you would a standard library. Figuring out the classpath can be confusing, but you can just set it when you start your jvm. Your IDE may have options for it, too.

    Most java problems are classpath problems.

    0 讨论(0)
  • 2020-12-08 14:42

    You should have documentation for these Jars. Some sounds like examples, but one must be the core graph modelling and rendering Jar. Hopefully the examples have source included.

    Just add that Jar to your project in Eclipse (e.g., in a /lib folder in your project, then add it to the build path) and use the documentation to use the code. You can also use Eclipse to look inside the Jar file.

    Unless there is no alternative, it probably isn't worth using a load of third party code that isn't documented at least on the API level, and without any source examples definitely not.

    0 讨论(0)
提交回复
热议问题