Java - using a downloaded package without an IDE

I am new to Java. I am still developing a simple text editor to better understand how package inclusion in Java.

I have a Test.java file whose first two lines:

import java.util.List;  
import com.google.gson.Gson;

I tried to download the google-gson package and unzip it in the same directory where Test.java is located.

| - google-gson-1.5
| | - gson-1.5.jar
| | - gson-1.5-javadoc.jar
| | - gson-1.5-sources.jar
| | - LICENSE
| `- README
`- Test.java

But when I try to run:

javac Test.java

I get this error message:

Test.java:2: package com.google.gson does not exist
import com.google.gson.Gson;

What to make everything work (using the command line and a simple editor)?

Thanks Dan

+3
source share
2 answers

Assuming Test.java is not assigned to the package:

Compile:

javac -cp .;google-gson-1.5\gson-1.5.jar Test.java

Run:

java -cp .;google-json-1.5\gson-1.5.jar Test

JAR:

javac -cp .;google-gson-1.5\gson-1.5.jar;anotherlib\anotherlib.jar Test.java

(: Windows. * Nix : ; / \)

javac java, build.bat run.bat ( build.sh run.sh on * Nix) javac java, . :

  • /
  • / - .
  • ,

Ant: java javac , , Ant , , .

+4

Java- , (, com.google.gson com\google\gson), gson-1.5.jar Classpath [ ].

, classpath javac .

+3

Source: https://habr.com/ru/post/1772962/


All Articles