Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8341969

java classpath list does not work on bash

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Pro 19045.4894
      java version "19" 2022-09-20
      Java(TM) SE Runtime Environment (build 19+36-2238)
      Java HotSpot(TM) 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Java class path list of directories does not work when Java is called from bash shell

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a directory lib and put in it this file Str.java:
          package lib;
           public class Str {
                   public int data;
           }
           and compile it: javac Str.java
      2. Create a directory apps and a subdirectory sublib in it and place this file in sublib:
           App.java
           package sublib;
           import java.io.*;
           import lib.Str;
           public class App {
               public static void main(String[] args){
                   Str s = new Str();
                   System.out.printf("%s\n",s.data);
               }
           }
          and compile it: javac -cp ../.. App.java (I am using the bash shell of cygwin)
      3. run the app:
              java -cp ..:../.. sublib.App


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The result should be:

            0
      ACTUAL -
      The result is:

      Error: Could not find or load main class sublib.App
      Caused by: java.lang.ClassNotFoundException: sublib.App

      The very same program, run from a Windows terminal works correctly.
      I have tried to swap the directories in the class path, to define the classpath as an environment variable, to use absolute paths instead of relative ones, but always with the same result. It is as if the classpath accepts a list of paths, but uses only the last one.

      ---------- BEGIN SOURCE ----------
      see above
      ---------- END SOURCE ----------

      FREQUENCY : always


            bchristi Brent Christian
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: