Error parsing file arguments error on jar with entry point creation

Viewed 590

I've create simple java project with single class - Main with main method printing Hello.

package com.foo;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello!");
    }
}

Code was compiled to bin directory. I'm trying to create jar using command

jar -cfe project.jar com.foo.Main -C bin\

with no results, always returning Error parsing file arguments error. I also tried many different variations, like

jar --create --file project.jar --main-class com.foo.Main -C bin

but none of it worked. I'm using Java 16

2 Answers

Try running this. It should create the 'project.jar'

jar --create --file project.jar --main-class com.foo.Main -C bin .

-C flag Temporarily changes directories (cd dir) during execution of the jar command while processing the following inputfiles argument.

This command changes to bin directory and adds to project.jar all files within the bin directory (without creating a bin directory in the jar file).

For more information check the -C part in the OPTIONS section : https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html#options

You need both a "=" after main-class and a "." at the end to selct al lthe files

jar --create --file project.jar --main-class=com.foo.Main -C bin .

or

jar cfe project.jar com.foo.Main -C bin .

Related