Reputation: 499
My work is currently having me take an intro to Java course. While I'm familiar with Python and python packages and virtual environments, I'm having trouble translating some of this to Java.
The course comes with its own IDE, which circumvents some of these issues, but the IDE won't launch and I'd rather understand packages from the start anyways. Once I get past this bump I can continue the tutorial.
My current directory structure looks like this:
project_dir
├── edu
│ └── edu_package
│ ├── all_files_in_edu_package.java
├── unicode.txt
├── Main.class
├── Main.java
The Main class relies on classes contained in the edu_package, and they seem to import well enough to throw an exception.
Here's the exception:
error: package org.apache.commons.csv does not exist
import org.apache.commons.csv.CSVFormat;
It seems i need a JAR file, but I cannot figure out if there's a pip install org
or pypi equivalent in Java.
Edit: The exception isn't throw in Main, it's thrown in the edu_package which is imported in Main.
Upvotes: 0
Views: 337
Reputation:
Follow this link of SO for understanding how to use jar
files.
You need to specify the downloaded jar files path while compiling or running you code.
Please download Apache Commons CSV from here after download extract the jar file commons-csv-1.9.0.jar
from the archive to a directory.
import org.apache.commons.csv.CSVFormat;
class MainClass{
public static void main(String ... $){
final var out = System.out;
out.println("Hell o world");
}
}
javac -cp '.:/home/devp/Documents/commons-csv-1.9.0.jar' MainClass.java
java -cp '.:/home/devp/Documents/commons-csv-1.9.0.jar' MainClass
Upvotes: 2