Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac problem: Not using the bundled JRE? #179

Open
charxie opened this issue Dec 31, 2020 · 20 comments
Open

Mac problem: Not using the bundled JRE? #179

charxie opened this issue Dec 31, 2020 · 20 comments
Labels

Comments

@charxie
Copy link

charxie commented Dec 31, 2020

We tried to bundled Java 8 but it seems it doesn't pick up the JRE. The command returned no error and the JRE was successfully copied into the Resources folder. Did anyone have the same issue?

@karlsabo
Copy link
Member

Which command? Are you trying to run your packed app? If so have you tried running from the command line with verbose output turned on? What other steps have you tried to debug the issue?

@lichenglu
Copy link

lichenglu commented Dec 31, 2020

Thanks for the fast reply @karlsabo. I am working with @charxie.

We are both testing in the MacOS environment. For your information. @charxie is using Oracle JDK 8 and the packed app works fine on his computer. However, it is not working for me and I am using OpenJDK 8. We have tried the following ways to run the executable. @charxie is the one who bundled the java app because it seems the app needs Oracle JDK 8 to run somehow.

  1. Double click Contents -> MacOS -> executable file
  2. Make the output folder an App by adding the .app extension

It only works if I run the jar file directly with ./jre/bin/java -jar [myapp].jar under Resources. That's why we are suspecting the executable in the MacOS directory is not using the shipped JRE.

Any thoughts? Thank you!

@karlsabo
Copy link
Member

Open a terminal and run
outdir/Contents/MacOS/executable-name --cli --verbose --

Where outdir is the output directory you specified when running packr-all.jar and executable-name is the name you specified for that too.

That should give some good hints as to what's going on.

@lichenglu
Copy link

Here are the outputs:

Changing working directory to outdir/Contents/Resources ...
Loading JVM runtime library ...
fileSearch found libjli! filename=jre/lib/jli/libjli.dylib, lastFileSearch=
Loading libjli=outdir/Contents/Resources/jre/lib/jli/libjli.dylib
Passing VM options ...
isZgcSupported()=1, hasJsonValue(jsonRoot, "useZgcIfSupportedOs", sajson::TYPE_TRUE)=0
  # -Xmx512M
Passing VM options:
  -Xmx512M
Creating Java VM ...
Passing command line arguments ...
Loading JAR file ...
Adding 1 classpaths ...
  # aladdin.jar
Invoking static org.aladdin.App.main() function ...
Initiating...
Checking single instance...
1.8.0_162, x86_64
Path = ./lib/jogl/native/mac-universal
Log folder: log
Initialization phase 2 done.
Time = 1.478569135
Checked for an exception from the main method, exceptionOccurred=0

Here is the error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

It does seem that the JRE is being used?

@karlsabo
Copy link
Member

Yes, it's using the bundled JRE, it would take some effort to get it to use anything else.

I bet your missing -XstartOnFirstThread as a JVM option.

@lichenglu
Copy link

Thank you! One last question, do we do like this?

java -jar packr-all.jar \
     --vmargs Xmx1G -XstartOnFirstThread \
     --...

Or we use use XstartOnFirstThread without the - (dash)? Because we have tried it without the dash, and the program will just hang there forever for both of us.

@karlsabo
Copy link
Member

Remove the leading dash.

Run with verbose and see if it gets any further. Also have you tried attaching a debugger or profiler such as visualVM to see what threads are hanging and where?

@charxie charxie closed this as completed Dec 31, 2020
@charxie
Copy link
Author

charxie commented Dec 31, 2020

Remove the leading dash.

Run with verbose and see if it gets any further. Also have you tried attaching a debugger or profiler such as visualVM to see what threads are hanging and where?

Did you mean run packr with verbose? We tried that but there was no more message.

@karlsabo
Copy link
Member

Did you get it working?

@charxie charxie reopened this Dec 31, 2020
@charxie
Copy link
Author

charxie commented Dec 31, 2020

Sorry, I accidentally closed the issue by mistake. This is the command we used:

java -jar packr-all-3.0.1.jar --platform mac --jdk /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk --executable Aladdin --classpath aladdin.jar --mainclass org.aladdin.App --vmargs Xmx512M XstartOnFirstThread --resources lib --output ala --verbose

And the output is:

Copying executable ...
Copying classpath(s) ...
Unpacking JRE ...
Copying resources ...
Done!

As lichenglu reported, with the XstartOnFirstThread argument, the app just hangs. Without the argument, it can run on my computer that has the original JDK (which I use to pack the app), but not any other Mac computers.

Thank you so much in advance for your help!

@karlsabo
Copy link
Member

karlsabo commented Dec 31, 2020

I meant to run the packr launcher executable in verbose mode.

ala/Contents/MacOS/Aladdin --cli --verbose --

If you have logging, you might be able to figure out where it's hanging, otherwise use jstack or VisualVM. jstack will give you a thread dump in the console, VisualVM is a bit nicer and easier to use.

@charxie
Copy link
Author

charxie commented Dec 31, 2020

This is what it outputs:

ala/Contents/MacOS/Aladdin --cli --verbose --
Changing working directory to /Users/ccuser/IdeaProjects/aladdin/out/artifacts/aladdin/ala/Contents/Resources ...
Loading JVM runtime library ...
fileSearch found libjli! filename=jre/lib/jli/libjli.dylib, lastFileSearch=
Loading libjli=/Users/ccuser/IdeaProjects/aladdin/out/artifacts/aladdin/ala/Contents/Resources/jre/lib/jli/libjli.dylib
Passing VM options ...
isZgcSupported()=1, hasJsonValue(jsonRoot, "useZgcIfSupportedOs", sajson::TYPE_TRUE)=0
  # -Xmx512M
  # -XstartOnFirstThread
Passing VM options:
  -Xmx512M
  -XstartOnFirstThread
Starting JVM on main thread (-XstartOnFirstThread found) ...
Creating Java VM ...
Passing command line arguments ...
Loading JAR file ...
Adding 1 classpaths ...
  # aladdin.jar
Invoking static org.aladdin.App.main() function ...
Initiating...
Checking single instance...
1.8.0_162, x86_64
Path = ./lib/jogl/native/mac-universal

@karlsabo
Copy link
Member

That looks good, definitely going to need to run jstack or VisualVM, the VM is up and running the code in aladdin.jar. Maybe it's hung on some JOGL call.

@charxie
Copy link
Author

charxie commented Dec 31, 2020

This app indeed uses Jogl. We will check. Is the VM argument a must in order to get it to work? How do you explain that it works on the computer that originally built it?

@karlsabo
Copy link
Member

Graphics APIs usually have to be called from the main threads. It's required on macOS if you're doing any UI stuff.

You can search for that VM parameter, it's hard to find any good info on it. https://www.eclipse.org/swt/faq.php#swtawtosxmore

My guess is your app is hung on a graphics or windowing call.

@charxie
Copy link
Author

charxie commented Dec 31, 2020

Thanks for your help! We will try again tomorrow!

@charxie
Copy link
Author

charxie commented Dec 31, 2020

You are right about the windowing call. The problem is that Mac has made a rule that is incompatible with Java Swing, which requires the initialization of Swing components to be in the AWT thread, not the main thread. Not sure how this problem can be solved.

@karlsabo
Copy link
Member

You could try putting everything in SwingUtilities.invokeLater calls. It's really hard to mix LWJGL 2 or JOGL with Swing.

Swing doesn't play nicely with startOnFirstThread but LWJGL, GLFW and afaik JOGL all require it.

@charxie
Copy link
Author

charxie commented Dec 31, 2020

My problem now boils down to the fact that the runnable in EventQueue.invokeLater (equivalent to SwingUtilities.invokeLater) doesn't run from the main thread. It just hangs there. Any idea?

@karlsabo
Copy link
Member

karlsabo commented Jan 4, 2021

I don't have any other ideas, but someone in the libGDX community might https://libgdx.badlogicgames.com/community.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants