0

I am completely new to Java, just learned a little because I need to run this project: https://github.com/ansjsun/ansj_seg

I have run

mvn compile

and some other stuff.

Now, in ansj_seg/target I have a file named ansj_seg-0.8.jar, which seems important, although I don't know how to use it.

In ansj_seg/src/test/java/org/ansj/demo, there are some demos, and I want to run BaseAnalysisDemo.java, I tried as following.

Step one, I compile using:

javac -classpath ~/Downloads/ansj_seg/target/ansj_seg-0.8.jar  BaseAnalysisDemo.java

It works fine and generates BaseAnalysisDemo.class.

But when I try to run it using

java BaseAnalysisDemo

An error occurs:

Exception in thread "main" java.lang.NoClassDefFoundError: BaseAnalysisDemo (wrong name: org/ansj/demo/BaseAnalysisDemo)

I guess I should set some path, but have no idea.

Anyone can help?

BTW, I prefer using command line to Eclipse.

The directory structure is like this(Updated):

\ansj_seg
    pom.xml
    \src
        \main
            \java
                \org
                    \ansj
                        \app
                        \dic
                        \domain
                        ...
            \resource
                ...
        \test
            \java
                \org
                    \ansj
                        \demo
                            BaseAnalysisDemo.java
                            Demo.java
                            ...
                        \test
                            ...

Here is another question, even if the demo can be run, how can I use this java library in another place? I guess the file ansj_set-0.8.jar should be used. Again, I know nothing about Java.. Any suggestion will be very helpful.


Updated:

If I run with classpath specified:

java -classpath ~/Downloads/ansj_seg/target/ansj_seg-0.8.jar BaseAnalysisDemo

still got an error, but different:

Exception in thread "main" java.lang.NoClassDefFoundError: BaseAnalysisDemo
HanXu
  • 5,507
  • 6
  • 52
  • 76
  • 1
    You will need to get someone who can read Chinese to help you. The documentation is all in Chinese. – Stephen C Aug 29 '13 at 13:36
  • **I am completely new to Java** : then avoid maven . **just first learn java the normal way **. [a question about maven benefits](http://stackoverflow.com/questions/3589562/why-maven-what-are-the-benefits) – Srinath Ganesh Aug 29 '13 at 13:40
  • This may not solve your current problem but you should use classpath you used while compiling also while running your application. – Pshemo Aug 29 '13 at 13:40
  • @Pshemo, I updated my post. I tried to specified the classpath when running, but still fail... – HanXu Aug 29 '13 at 13:51
  • @StephenC, I think to run the project requires no knowledge of Chinese..all source code and demo code are there..just compile and link problem... – HanXu Aug 29 '13 at 13:53

1 Answers1

0

You will fall back to Eclipse soon, because what you'd like to do is a bit cumbersome, but doable.

Try this:

mvn exec:java -Dexec.mainClass="java.org.ansj.demo.BaseAnalysisDemo.java"

If you need arguments too, add -Dexec.args to the list.

Note that you'll have to move your demo under the main source tree.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • I still cannot get it work..and I decide to learn Eclipse..anyway..thank you very much! – HanXu Aug 29 '13 at 14:52
  • What is the exact error you get? Have you tried to run this where you have your `pom.xml` file? – rlegendi Aug 29 '13 at 15:25
  • I updated my original post. Please refer to the directory structure. I am in the directory \ansj_seg, and running the code you give me. An error occurs:"java.lang.ClassNotFoundException: java.org.ansj.demo.BaseAnalysisDemo.java". Plus, I tried to use Dexec.mainClass="src.test.java.org.ansj.demo.BaseAnalysisDemo.java" and Dexec.mainClass="test.java.org.ansj.demo.BaseAnalysisDemo.java", still not work... – HanXu Aug 30 '13 at 01:16
  • Do not put `src`/`test` to the classname, because it is not in your package declaration. You can only refer to classes under the `src` dir this way, test sources are available only under testing. Your package declarations are correct, I checked at Github. Put the demo class under `src`, as I suggested. – rlegendi Aug 30 '13 at 10:29