简体   繁体   中英

Setting the classpath in a Visual Studio Code Maven-based Java project

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.

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.

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

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

 import.com.abbyy.FREngine.*;

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

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.

Any suggestions?

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

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

I didn't find this jar in online maven repositories. It means you can't add this jar as a dependency in your pom.xml without uploading the jar in your local maven repository.

the following is a solution picked from https://forum.ocrsdk.com/thread/5116-frengine-11-maven-is-not-supported/

First you need to upload the jar in your maven repository using

mvn install:install-file -Dpackaging=jar -DgeneratePom=true -Dclassifier=win -DgroupId=com.abbyy.FREngine -DartifactId=com.abbyy.FREngine.jar -Dversion=11 -Dfile=local_path_to_the_jar_file

Then you can use the dependency in your pom.xml using :

<dependency>
 <groupId>com.abbyy.FREngine</groupId>
 <artifactId>com.abbyy.FREngine.jar</artifactId>
 <version>11</version>
 <classifier>${os.prefix}</classifier>
</dependency>

The "classifier" used in the solution is required because it seems like the jar you're using embed some native compiled code (dll or so files). You need to check if your jar embeds .dll or .so files or both

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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