Skip to content

Visual Code and jar files #501

@danielcalvogonzalez

Description

@danielcalvogonzalez

Hello all,

I'm pretty sure this is a silly question but this is driving me crazy as I don't know what to do to work it out. I am not a Java expert although I have some programming skills. I'm trying to use Visual Code + Java Extension Pack as I thought it could be a good combination.

I am not using any project (eclipse, maven, etc) as I'm only creating short and straightforward programs. The problem I'm facing is when I try to use some classes from a jar file (for instance, algs4.jar from https://algs4.cs.princeton.edu/code/algs4.jar)

I create a simple java file in a directory that uses some of the classes with an import directive and I've added the directory where algs4.jar resides to my classpath (operating system) variable. From the command line, I can run successfully javac and java command, so everything looks fine (no errors, no warning, etc). I can compile and run my program. But when I try to run my java file from Visual Code, I receive the following error:

The import edu cannot be resolved
The import edu cannot be resolved
StdRandom cannot be resolved
StdRandom cannot be resolved
StdStats cannot be resolved
StdStats cannot be resolved

at PercolationStats.<init>(PercolationStats.java:7)
at PercolationStats.main(PercolationStats.java:105)

It clearly shows that Visual Code can't find the jar file but I don't know what to do to teach VC where that file resides.

Would kindly someone help me to work this problem out? By the way, where can I find more information about the usage of VC + Java?

Thank you very much.

Environment
  • Operating System: Windows 10
  • JDK version: 1.8.0_161
  • Visual Studio Code version: 1.22.1
  • Java extension version: Language Support for Java by Red Hat v0.22.0
Additional information

These are my import lines

import edu.princeton.cs.algs4.StdRandom;
import edu.princeton.cs.algs4.StdStats;


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions