简体   繁体   English

我如何开始使用JFreeChart?

[英]How do I get started with JFreeChart?

I've never used any third party library before. 我以前从未使用过任何第三方库。 What should I do after I downloaded jfreechart-1.0.14.tar.gz ? 下载jfreechart-1.0.14.tar.gz后该怎么jfreechart-1.0.14.tar.gz

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. 1.将jcommon-1.0.17.jarjfreechart-1.0.14.jar与我的源代码放在同一目录中。
2. Import needed class in the source code (eg import org.jfree.util.Rotation; ) 2.在源代码中导入所需的类(例如, import org.jfree.util.Rotation;

Many articles tell you how to do this in IDEs. 许多文章告诉您如何在IDE中执行此操作。 But instead of IDEs, I'm writing codes with vim and compile by myself. 但是我不是用IDE,而是用vim编写代码并自己编译。 So, assume I didn't do any thing wrong, how should I compile the source code with javac and run the code with java ? 因此,假设我没有做错任何事情,我该如何使用javac编译源代码并使用java运行代码?


Edit: 编辑:

Here's my file layout: 这是我的文件布局:
./src ./src
| | - test.java -test.java
./lib ./lib
| | - jcommon-1.0.17.jar -jcommon-1.0.17.jar
| | - jfreechart-1.0.14.jar -jfreechart-1.0.14.jar

I compile by 我编译
javac -cp "lib/*" -d classes/ src/test.java
then run by 然后跑
java -cp classes:lib/jcommon-1.0.17.jar:jfreechart-1.0.14.jar test

However, some error occurs: 但是,会发生一些错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset 线程“主”中的异常java.lang.NoClassDefFoundError:org / jfree / data / general / PieDataset

How can I resolve this problem? 我该如何解决这个问题?


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

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: 如果您还不想使用像Gradle这样的构建工具来处理您的库依赖项,那么建议您使用以下布局:

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

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

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