在基于Visual Studio Code Maven的Java项目中设置类路径 [英] Setting the classpath in a Visual Studio Code Maven-based Java project

查看:1089
本文介绍了在基于Visual Studio Code Maven的Java项目中设置类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CentOS 7上使用Visual Studio Code来运行/调试第三方供应商提供的现有Hello World Java项目.我是Java的新手,所以也许我缺少一些明显的东西.

I'm attempting to use Visual Studio Code on CentOS 7 to run/debug an existing Hello World Java project from a third party vendor. I am relatively new to Java, so perhaps there is something obvious that I'm missing.

我已经在此处中描述了扩展名,从而设置了Visual Studio Code.我还设置了Apache Maven,并能够在Visual Studio Code中创建一个新的Maven Java项目,该项目可以进行编译和调试.现在,我想获取第三方供应商的Hello World示例(不使用Maven),并将其合并到工作的Maven示例中.

I've set up Visual Studio Code with the extensions described here. I have also set up Apache Maven and was able to create a new Maven Java project in Visual Studio Code which compiles and can be debugged. Now I want to take the third party vendor's Hello World sample (which doesn't use Maven) and incorporate it into the working Maven sample.

我能够从命令行编译并运行第三方供应商未修改的Hello World应用程序.从命令行构建它时,我需要运行一个包含以下内容的build.sh脚本:

I'm able to compile and run the third party vendor's untouched Hello World app from the command line. When I build it from the command line, I need to run a build.sh script which contains the following:

 #!/bin/sh
 "$JDK/bin/javac" -classpath ".:..:../../../Inc/Java/com.abbyy.FREngine.jar" \ Hello.java

当我将原始Java代码复制并粘贴到Maven项目中的主Java文件中时,此行...

When I copy and paste the original Java code into my main Java file in the Maven project, this line...

 import.com.abbyy.FREngine.*;

...在尝试编译时,可理解地显示了无法解析导入com.abbyy"错误.

...understandably shows a "The import com.abbyy cannot be resolved" error when trying to compile.

看来我需要在项目的某个地方设置类路径...但是我不知道在哪里.是的,我的项目中有一个".classpath"文件,但是该信息应该存放在哪里……还是根本不在该文件中,这并不明显.

It appears that I need to set the classpath somewhere in my project...but I can't figure out where. Yes, there's a ".classpath" file in my project, but it's not obvious where this information should go...or if it should in that file at all.

有什么建议吗?

推荐答案

我可以通过将以下条目添加到.classpath文件中来解决我的问题:

I was able to solve my issue by adding this entry to the .classpath file:

 <classpathentry kind="lib" path="/opt/ABBYY/FREngine12/Inc/Java/com.abbyy.FREngine.jar" />

这篇关于在基于Visual Studio Code Maven的Java项目中设置类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆