Repository: GoogleContainerTools/jib
File: jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/JarModeProcessor.java (Java)

Code before:

    layers.add(resourcesLayer);
    layers.add(classesLayer);
    return layers;
  }

  /**
   * Creates layers for dependencies, snapshot dependencies and the jar itself on container for a
   * standard jar.
   *
   * @param jarPath path to jar file
   * @return list of {@link FileEntriesLayer}
   * @throws IOException if I/O error occurs when opening the jar file
   */
  static List<FileEntriesLayer> createPackagedModeLayersForStandardJar(Path jarPath)
      throws IOException {
    // Add dependencies layers.
    List<FileEntriesLayer> layers = getDependenciesLayers(jarPath);

    // Add layer for jar.
    FileEntriesLayer jarLayer =
        FileEntriesLayer.builder()
            .setName(JAR)
            .addEntry(
                jarPath,
                APP_ROOT.resolve(RelativeUnixPath.get("jar")).resolve(jarPath.getFileName()))
            .build();

    layers.add(jarLayer);
    return layers;
  }

  /**
   * Computes the entrypoint for a standard jar in exploded mode.
   *
   * @param jarPath path to jar file
   * @return list of {@link String} representing entrypoint
   * @throws IOException if I/O error occurs when opening the jar file
   */
  static ImmutableList<String> computeEntrypointForExplodedStandard(Path jarPath)
      throws IOException {
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String mainClass =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
      if (mainClass == null) {
        throw new IllegalArgumentException(
            "`Main-Class:` attribute for an application main class not defined in the input JAR's "
                + "manifest (`META-INF/MANIFEST.MF` in the JAR).");
      }
      String classpath = APP_ROOT + "/explodedJar:" + APP_ROOT + "/dependencies/*";
      return ImmutableList.of("java", "-cp", classpath, mainClass);

Review comment (suggestion):
Oh, I remember we decided to do `java -jar`. In that case, we should retain the directory structure for the dependencies given in `Class-Path:` in `MANIFEST.MF`.

Code after:
   * standard jar.
   *
   * @param jarPath path to jar file
   * @return list of {@link FileEntriesLayer}
   * @throws IOException if I/O error occurs when opening the jar file
   */
  static List<FileEntriesLayer> createLayersForPackagedStandard(Path jarPath) throws IOException {
    // Add dependencies layers.
    List<FileEntriesLayer> layers = getDependenciesLayers(jarPath, ProcessingMode.packaged);

    // Add layer for jar.
    FileEntriesLayer jarLayer =
        FileEntriesLayer.builder()
            .setName(JAR)
            .addEntry(jarPath, APP_ROOT.resolve(jarPath.getFileName()))
            .build();
    layers.add(jarLayer);

    return layers;
  }

  /**
   * Computes the entrypoint for a standard jar in exploded mode.
   *
   * @param jarPath path to jar file
   * @return list of {@link String} representing entrypoint
   * @throws IOException if I/O error occurs when opening the jar file
   */
  static ImmutableList<String> computeEntrypointForExplodedStandard(Path jarPath)
      throws IOException {
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String mainClass =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
      if (mainClass == null) {
        throw new IllegalArgumentException(
            "`Main-Class:` attribute for an application main class not defined in the input JAR's "
                + "manifest (`META-INF/MANIFEST.MF` in the JAR).");
      }
      String classpath = APP_ROOT + "/explodedJar:" + APP_ROOT + "/dependencies/*";
      return ImmutableList.of("java", "-cp", classpath, mainClass);
    }
  }

  /**
   * Computes the entrypoint for a standard jar in packaged mode.
   *
   * @param jarPath path to jar file
   * @return list of {@link String} representing entrypoint
   * @throws IOException if I/O error occurs when opening the jar file
   */
  static ImmutableList<String> computeEntrypointForPackagedStandard(Path jarPath)