Jorl17 / jar2app

Convert any Java jar to a Mac OS X .App bundle. No external tools needed, no funky parameters, it just works.
GNU General Public License v2.0
418 stars 56 forks source link

jar to app with args #33

Open mfouka opened 6 years ago

mfouka commented 6 years ago

I would like to pack a java application with script my script starts with java -jar myapp.jar file.txt to convert it to macos I converted my jar with your tools but the problem when I run open -n myapp.app file.txt the program does not see the arguments?

Lucina commented 6 years ago

You're supposed to use --args before your arguments. Fairly certain you'll find that <app>/Contents/MacOS/<JavaAppLauncher or your custom named stub> <args> works fine as well.

nfouka commented 6 years ago

We Can change the name of the JavaAppLauncher script? We have to do something like that java -jar myapp.jar $ 1? or fill in the <args>?

Lucina commented 6 years ago

JavaAppLauncher (the default name) is the app's stub executable that by default just runs the jar as if by java -jar whatever.jar. In place of <args> in your case would be file.txt The full invocation would be myapp.app/Contents/MacOS/JavaAppLauncher file.txt As for the executable name, the jar2app readme lists -e as an option. -e EXECUTABLE, --executable-name=EXECUTABLE Name of the internal executable to launch (Default: JavaAppLauncher).

nfouka commented 6 years ago

Thanks for your feedback, I regenerated my .app with a shell / bin / bash executable run.sh:

! /Bin/bash

java -jar Contents/Java/myjar.jar $ 1

and I was pointing during the generation of my .app --executable-name = run.sh but when I run the executable nothing starts!

Lucina commented 6 years ago

That's not what --executable-name is intended for. It's for being able to rename the standard JavaAppLauncher stub to whatever name you want the built app to use. If you were to name it run.sh, I'd imagine the name would be applied but wouldn't execute properly as having a shell script be the main executable of a .app bundle is... Odd. Try building the app as you originally did but run it with open -n -a myapp.app --args file.txt This should be the most straightforward way. Tell me if that doesn't work, my MacBook's in the shop so I can't really test this.

nfouka commented 6 years ago

I tested with command open -n -a myapp.app --args file.txt , but it does not work!

Lucina commented 6 years ago

What do you get in the terminal, and does the app launch

nfouka commented 6 years ago

The application does not launch, no message on the console !

nfouka commented 6 years ago

I tested on high sierra and it opens with the command open myapp.app --args file.txt (open without option) On the other hand when I open my file from the desktop and I double click (or open with myapp.app) my application starts but she still does not see the file do you have an idea ? Thank you

Lucina commented 6 years ago

So.. You're saying open myapp.app --args file.txt opens the app and it recognizes the passed argument?

If you want the app to automatically use the file like that whenever you double-click the app, shouldn't you just refactor that into your code as a constant File field somewhere and ignore the arguments? Alternatively, you could modify the built app to execute a script or create a script app.

nfouka commented 6 years ago

Yes exactly I tested it on Sierre Height and El Capitan Thank You

Lucina commented 6 years ago

Sorry. I assumed the stub recognizes arguments. It doesn't. Either you rely on making the jar launch through a shell script instead of bundling an app or hardcode the file name into your program. Doesn't seem possible to make arguments work here.

Lucina commented 6 years ago

Heh. Added PR #34, which you should be able to use with the likes of universalJavaApplicationStub to get arguments working.

Once I used jar2app from that PR with -x universalJavaApplicationStub (universalJavaApplicationStub downloaded from the repo linked above was in the same directory as the jar I packaged), I was able to get arguments working as expected.

screen shot 2018-11-29 at 6 41 44 pm screen shot 2018-11-29 at 7 41 53 pm

I doubt that the PR will get merged any time soon (given both splash PRs have been idle for ages) so you can just download my fork's branch if you want.

Jorl17 commented 6 years ago

Hi!

As you can tell, I don't at the moment have very much time to give the support I want to in any of my projects, but I've merged the pending PRs. Do you confirm they are working?

If you need anything else, do say, I'll try to find some free time between work and side-project work to fit in gratis-side-project work :)

Thank you for your developments!

Lucina commented 6 years ago

Yes, I tested the user-provided stub PR with multiple cases on my programs (no customization, custom name only, custom stub only [name is kept to default JavaAppLauncher], custom name + custom stub [stub is copied with a new name). It works as you'd expect. Seriously, thanks for making this amazing project.

nfouka commented 6 years ago

Great Work ! Thank You.

Lucina commented 5 years ago

Is your issue resolved / do you want to close this issue?