1

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?

Andr
  • 1,043
  • 4
  • 13
  • 15
  • 1
    Add that jar using `mvn install:file`. See the [Maven Guide to installing 3rd party JARs](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html) and modify the `pom.xml` to include your local 3rd-party jar. – Elliott Frisch Jun 07 '18 at 20:24

2 Answers2

2

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" />
Andr
  • 1,043
  • 4
  • 13
  • 15
  • 1
    I know this is a year old, but THANKS!! Just started using VS Code for Java and couldn't figure this one out. (I'm not experienced with Maven.) – ke4ktz Jun 27 '19 at 11:30
0

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

Mumrah81
  • 2,034
  • 2
  • 16
  • 23
  • Thanks for the tip. I am stuck at the first step, though, with uploading the jar in the Maven repository. It appears that the jar file itself has no version number, so Maven complains `"The artifact information is incomplete or not valid: [0] 'version' is missing"` - it doesn't matter what DVersion is set to. When I run `unzip -p com.abbyy.FREngine.jar META-INF/MANIFEST.MF` I get back the following: `Manifest-Version:1.0 Created-By: 1.7.0_80 (Oracle Corporation)` My understanding is that the version number is actually `Implementation-Version`, which this jar file does not have. – Andr Jun 08 '18 at 18:16
  • I've tested the command with a sample jar file and it worked fine. The version parameter you need to provide is an arbitrary number/string that don't have anything to do with any value in the manifest file. Can you share the command generating the error message? – Mumrah81 Jun 08 '18 at 22:14