0

I have a file Test.java (stripped down for debugging):

import com.github.tkutche1.jgrade.Grade;

I try compiling it with this command line and get an error:

# javac -cp lib/com/github/tkutche1/jgrade/Grade.class:. Test.java
Test.java:1: error: package com.github.tkutche1.jgrade does not exist
import com.github.tkutche1.jgrade.Grade;
                                 ^
1 error

The package does exist, as shown:

# javap lib/com/github/tkutche1/jgrade/Grade.class

Compiled from "Grade.java"
public interface com.github.tkutche1.jgrade.Grade extends java.lang.annotation.Annotation {
}

Here's what happens with the verbose command line option [with added line breaks]:

# javac -verbose -cp lib/com/github/tkutche1/jgrade/Grade.class:. Test.java
[parsing started RegularFileObject[Test.java]]
[parsing completed 15ms]
[search path for source files: lib/com/github/tkutche1/jgrade/Grade.class,.]
[search path for class files: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar,
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar,
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar, /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/classes,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/nashorn.jar,
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jaccess.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunpkcs11.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunjce_provider.jar, 
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/icedtea-sound.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/dnsns.jar,
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/java-atk-wrapper.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/zipfs.jar,/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/cldrdata.jar, /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunec.jar,
lib/com/github/tkutche1/jgrade/Grade.class,.]
Test.java:2: error: package com.github.tkutche1.jgrade does not exist
import com.github.tkutche1.jgrade.Grade;
                                 ^
[total 111ms]
1 error

I am using javac 1.8.0_352 on Ubuntu. (I am trying to create a Gradescope autograder.)

I have read the answers to many similar questions, which say to include the .class file (or .jar file) in the classpath, which I have done. None of the questions have the output of javap showing that the package exists in the specified class.

What am I doing wrong?

1 Answer 1

1

The valid entries on the Java classpath are:

  1. Directories containing compiled package trees ... whose names match the package name structure
  2. Individual JAR files
  3. JAR file wildcards

Entries that are none of the above will be silently ignored.

You have put an individual .class file on the classpath. It will be ignored.

Assuming that "lib" is a directory that contains "com/github/tkutche1/jgrade/Grade.class", your classpath should be:

$ javac -cp lib:. ....

Not the answer you're looking for? Browse other questions tagged or ask your own question.