开发者

Compiling a java package with Libraries in windows CMD

I have a Java package containing one class I'm trying to compile in windows CMD.

Here's the folder structure:

Compiling a java package with Libraries in windows CMD

.\src\ contains the packages. I'm trying to compile the class inside the AggregationEngine package. The class is called testClass.java and it uses the twitter4j library. The jar files of the twitter4j library are included in the .\src\lib\ directory as twitter4j-core-2.2.4.jar

I tried the following:

javac -classpath "..\lib\twitter4j-core-2.2.4.jar" -sourcepath C:\x\x\x\src\AggregationEngine\ AggregationEngine\TwitterCrawler.java

java AggregationEngine.testClass "test String"

pause

but it doesn't seem to work. I have a basic understanding of the above. I'm not even sure if the above is the correct way to do it.

Note: I don't want to go into the Environment variable definition method, because I'm gonna do the same on a different OS. Oh and I might also include multiple .jar files as well.

-- Edit -- Output: when running the app. java AggregationEngine.TwitterCrawler

Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException
Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.Access开发者_开发技巧Controller.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)

Any advice?


Your problem is simply that the twitter4j JAR is missing when you try to execute your program. The compiler only uses classpath entries to verify the correctness of the code, it does not include them into its output.

This should work:

java -classpath .;..\lib\twitter4j-core-2.2.4.jar AggregationEngine.testClass "test String"


Could you use ant ? it's probably the easiest way of doing it :)

http://ant.apache.org/


...or Maven, including Twitter4j in your Maven project is explained in http://twitter4j.org/en/index.html#maven


I know it's too old but for those like me - the problem of ClassNotFound for TwitterException was solved by including log4j, slf4j and commons-logging jars in the project since twitter4j core uses them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜