我如何开始使用JFreeChart? [英] How do I get started with JFreeChart?
问题描述
我之前从未使用过任何第三方库。我下载 jfreechart-1.0.14.tar.gz
后该怎么办?
I've never used any third party library before. What should I do after I downloaded jfreechart-1.0.14.tar.gz
?
我不知道如果我正确地做这些事情:
1.把 jcommon-1.0.17.jar
和 jfreechart-1.0 .14.jar
与我的源代码位于同一目录。
2.在源代码中导入所需的类(例如 import org.jfree.util .Rotation;
)
I don't know if I'm doing these things right:
1. Put the jcommon-1.0.17.jar
and jfreechart-1.0.14.jar
at the same directory as my source code.
2. Import needed class in the source code (e.g. import org.jfree.util.Rotation;
)
许多文章都告诉你如何在IDE中做到这一点。但是我没有使用IDE,而是用vim编写代码并自己编译。所以,假设我没有做任何错误,我应该如何使用 javac
编译源代码并使用 java $ c运行代码$ C>?
Many articles tell you how to do this in IDEs. But instead of IDEs, I'm writing codes with vim and compile by myself. So, assume I didn't do any thing wrong, how should I compile the source code with javac
and run the code with java
?
编辑:
这是我的文件布局:
./src
| - test.java
./lib
| - jcommon-1.0.17.jar
| - jfreechart-1.0.14.jar
Here's my file layout:
./src
| - test.java
./lib
| - jcommon-1.0.17.jar
| - jfreechart-1.0.14.jar
我编译
javac -cplib / *-d classes / src / test.java
然后运行
java -cp类:lib / jcommon-1.0.17.jar :jfreechart-1.0.14.jar test
但是,发生了一些错误:
线程main中的异常java.lang.NoClassDefFoundError:org / jfree / data / general / PieDataset
However, some error occurs:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
如何解决此问题?
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.general.PieDataset
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
推荐答案
库不应与源代码位于同一位置。如果您不想使用像Gradle那样的构建工具,它会处理您的库依赖项,那么我建议使用以下布局:
The libraries shouldn't be at the same place as the source code. If you don't want to use a build tool like Gradle yet, which would handle your library dependencies, then I suggest using the following layout:
project
src
.java files here, organized in a folder tree matching the package tree
classes
compiled .class files here
lib
.jar files here
要编译,请进入项目目录并执行以下命令:
To compile, go in the project directory and execute the following command:
javac -cp lib/jfreechart-1.0.14.jar:lib/jcommon-1.0.17.jar -d classes src/com/foo/bar/MyClass.java src/com/foo/bar/MyOtherClass.java
运行你的应用程序,执行以下命令:
To run your app, execute the following command:
java -cp classes:lib/jfreechart-1.0.14.jar:lib/jcommon-1.0.17.jar com.foo.bar.MyClass
这篇关于我如何开始使用JFreeChart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!