在windows CMD中用Libraries编译java包

发布于 2024-12-04 16:05:27 字数 1397 浏览 2 评论 0原文

我有一个 Java 包,其中包含我试图在 Windows CMD 中编译的一个类。

这是文件夹结构:

文件夹结构

.\src\ 包含包。我正在尝试编译 AggregationEngine 包内的类。该类名为 testClass.java,它使用 twitter4j 库。 twitter4j 库的 jar 文件包含在 .\src\lib\ 目录中,作为 twitter4j-core-2.2.4.jar

I尝试了以下方法:

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

但似乎不起作用。通过以上我已经有了基本的了解。我什至不确定上述方法是否正确。

注意:我不想进入环境变量定义方法,因为我要在不同的操作系统上执行相同的操作。哦,我还可能包含多个 .jar 文件。

- 编辑 - 输出:运行应用程序时。 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.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)

有什么建议吗?

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

Here's the folder structure:

Folder structure

.\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.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)

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

海未深 2024-12-11 16:05:27

您的问题很简单,当您尝试执行程序时,twitter4j JAR 丢失了。编译器仅使用类路径条目来验证代码的正确性,不会将它们包含在其输出中。

这应该有效:

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

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"
亽野灬性zι浪 2024-12-11 16:05:27

你能用蚂蚁吗?这可能是最简单的方法:)

http://ant.apache.org/

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

http://ant.apache.org/

ヅ她的身影、若隐若现 2024-12-11 16:05:27

...或 Maven,在 Maven 项目中包含 Twitter4j 的说明在 http://twitter4j.org/en/index.html#maven

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

挥剑断情 2024-12-11 16:05:27

我知道它太旧了,但对于像我这样的人来说 - TwitterException 的 ClassNotFound 问题是通过在项目中包含 log4j、slf4j 和 commons-logging jar 来解决的,因为 twitter4j 核心使用了它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文