user2243772
user2243772

Reputation: 23

can't take name of running jar

I know there are a lot of similar questions and answers. But no one solution work for me! I don't understand why(( So I have runnable jar for example 'program.jar' and inside of it I want to take name of this jar (namely program.jar). I've tried following:

And in all these cases I can take only path to this jar. For example full path is J:/folder/program.jar. All that I can see are J:/folder.

What's the mistake? I'm trying to get name of jar in main class and others.

I've tried to run this jar by double click and with command line. Result is the same

Upvotes: 0

Views: 243

Answers (1)

martinez314
martinez314

Reputation: 12332

Try this:

(new File(ClassInsideJar.class.getProtectionDomain().getCodeSource().getLocation().toURI())).getName();

Upvotes: 1

Related Questions