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

jar entry point not working within the same directory

XMLWordPrintable

    • jar
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      java version "19" 2022-09-20

      A DESCRIPTION OF THE PROBLEM :
      Setting an entry point when creating a jar from within the directory that contains
      the main class does not work.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. create a directory jartest and cd into it
      2. compile the Main.java program: javac Main.java
      3. create the jar: jar cfe main.jar jartest.Main Main.class
      4. run the jar: java -jar main.jar

      ACTUAL -
      Error: Could not find or load main class jartest.Main
      Caused by: java.lang.ClassNotFoundException: jartest.Main

      ---------- BEGIN SOURCE ----------
      package jartest;
      public class Main {
          public static void main(String[] args){
             System.out.printf("Hi\n");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You need to create the jar in the parent directory:
      cd ..
      jar cfe jartest\main.jar jartest.Main jartest\Main.class
      cd jartest

      N.B. jartest.Main is present in the jar archive, so it is rather strange to have to
      cd into the parent directory to create the jar archive

      FREQUENCY : always


        1. Main.java
          0.1 kB
          Anjana Sajeev

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: