Question

I am trying to add two class files to .jar file. I am using the command:

jar cfve CashFlow.jar cashFlowCalculator cashFlowCalculator.class cashFlowCalculator$1.class

But this is only adding the cashFlowCalculator.class file, while ignoring the $1.class. There aren't even any errors, it's just never mentioned. It is not added to the .jar. Adding the $1.class manually seems to fix the issue of the program not running.

This is with Oracle JDK 8, if that is any help.

Was it helpful?

Solution

This has nothing to do with the jar command, but has everything to do with how the command line works. Basically, $1 is evaluated at the command line as "Var 1". So, as far as the jar command is aware, you are telling it to add "cashFlowCalculator.class" twice. Don't believe me? Run this on your command shell:

echo cashFlowCalculator.class cashFlowCalculator$1.class

and you will see

cashFlowCalculator.class cashFlowCalculator.class

Because $1 evaluates to "empty" as it is very likely undefined.

Instead, try this line for your jar command:

jar cfve CashFlow.jar cashFlowCalculator cashFlowCalculator.class cashFlowCalculator\$1.class

And that should work.

OTHER TIPS

If you are using eclipse, you can go File > Export > Java > Runnable Jar....and select the class with the main method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top