Java Error: Could not initialize class sun.lwawt.macosx.LWCToolkit

Hi,

So I’ve run into error that I’ve not encountered before when using VP and more specifically, using the plugin scripts mechanism.

To give some context, we use a Mac VM to execute scripts throughout the day. When I’m connected to the device using Screen Sharing, I am able to execute these commands from within the terminal no problem. eg; example of updating a VP project using the plugin script

cd "/Applications/Visual Paradigm.app/Contents/Resources/app/scripts/" && sh UpdateTeamworkProject.sh -workspace "/Users/x/Library/Application Support/VisualParadigm/ws/" -project "/Users/x/Library/Application Support/VisualParadigm/ws/teamwork_client/projects/y/y.vpp"

However when accessing the device using ssh and running the same script as above, I get the following error from java:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.lwawt.macosx.LWCToolkit
	at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:47)
	at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:592)
	at java.desktop/sun.awt.CGraphicsEnvironment.<clinit>(CGraphicsEnvironment.java:73)
	at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:43)
	at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:93)
	at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:84)
	at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106)
	at v.aid.ad.a(:299)
	at v.aid.ad.g(:261)
	at v.avz.bm.a(:834)
	at v.avz.bm.a(:239)
	at v.avc.b.a(:83)
	at com.vp.cmd.UpdateTeamworkProject.a(:38)
	at com.vp.cmd.UpdateTeamworkProject.main(:23)

I am running the following version of VP: 16.1 and the current Java version is: 8 update 301.

Any help on this would be much appreciated.

Hi GregS,

Thank you for your post. Could you send me your log file for diagnosis? The article below shows you how to obtain the log:

Then, please upload to:
https://files2.visual-paradigm.com/index.php/s/6avhY0Sq6NXlZwF

Password:
jg67ogfe0ds65hvjdf

Note: Only Visual Paradigm staff can access the uploaded files.

Best regards,
Jick Yeung

Thanks for responding @Jick . I’ve just uploaded the log file.

UPDATE:
I’ve just done some further investigation. Within the Screen Sharing app, I opened up VP on the Mac VM; I also ssh onto the Mac VM and I executed the command shared in the original post. In doing so, it returns the following error:

Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Workspace in use.

However, if I then create a new workspace, try to rerun the command using ssh in the terminal, I still get the same error as in the OP. It’s almost as though it can’t initialise the application or something when remotely connecting to that device.

I have tried doing the same approach as above but on an physical device (Mac Mini) as opposed to a VM and this doesn’t throw any problem. It updates a given project fine.

Hi GregS,

I have just downloaded your file and will forward it to our engineers to study. When there is any update, I will post it here.

Best regards,
Jick Yeung

Hi GregS,

Could you try to set the environment variable HEADLESS=true before running the script?

Best regards,
Jick Yeung

Hi Jick,

Thanks for responding. I assume add that to the plugin.sh file? Currently its set to false.

Hi GregS,

I have forwarded your question to our engineers and will share the answer with you asap.

Best regards,
Jick Yeung

Hi GregS,

Set the environment variable for a single session:
export HEADLESS=true

or you can modify the plugin.sh file to change it permanently.

Best regards,
Jick Yeung

Hi Jick,

I have updated the plugin.sh file with the change you mentioned however the java.lang.NoClassDefFoundError still persists when ssh onto the Mac VM.

plugin.sh file below:

#!/bin/sh
cd ../bin
if [ "v$HEADLESS" = "v" ]; then
    HEADLESS=true
fi

JAVA="../jre/bin/java"
if [ ! -f "$JAVA" ]; then
    JAVA="../../jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="../../jre.bundle/Contents/Home/jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="../../.install4j/jre.bundle/Contents/Home/jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="java"
fi

"$JAVA" -Xms4096m -Xmx8192m -XX:MaxPermSize=4096m -Djava.awt.headless=$HEADLESS -cp ...

You mentioned setting the environment variable for a single session, where in VP or what config file do I need to set this?

Hi GregS,

I will consult our engineers and get back to you as soon as I can.

Best regards,
Jick Yeung

Hi GregS,

Is the trace the same? It could be the same error but with a different trace. If the trace is the same, then it is likely that the headless variable wasn’t applied correctly… If the trace is different, could you send me to have a look?

Best regards,
Jick Yeung

HI @Jick

Yes, the stack is the same error. Error shown below:

Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.lwawt.macosx.LWCToolkit
	at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:47)
	at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:597)
	at java.desktop/sun.awt.CGraphicsEnvironment.<clinit>(CGraphicsEnvironment.java:72)
	at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:43)
	at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:93)
	at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:84)
	at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106)
	at v.aid.ad.a(:299)
	at v.aid.ad.g(:261)
	at v.avz.bm.a(:834)
	at v.avz.bm.a(:239)
	at v.avc.b.a(:83)
	at com.vp.cmd.UpdateTeamworkProject.a(:38)
	at com.vp.cmd.UpdateTeamworkProject.main(:23)

The log file contains the following:

[2021/08/17 08:45:28] [message] Aug 17, 2021 8:45:28 AM com.jidesoft.plaf.aqua.AquaPreferences loadGlobalPreferences

WARNING: AquaPreferences failed to load Mac OS X global system preferences - parseInt: unsupported byte count:16

[2021/08/17 08:45:28] [message] Connect to repository https://x.vpository.com [Success]

Just to add, I am running Big Sur on the Mac VM. The device in which it was working successfully on was using Catalina.

Hi GregS,

I’ve forwarded your reply to our engineers to study. When there is any news, I will let you know.

Best regards,
Jick Yeung

Hi GregS,

First of all, please try to set in the environment variable, run:
“HEADLESS=true ./plugin.sh”

We have developed a test program to help to diagnose the problem. Please down the zip here:

Then, unzip the downloaded file to obtain the Test.class file. Copy the Test.class file to the script folder. Then, change the last line of plugin.sh to:
“$JAVA” -Xms4096m -Xmx8192m -XX:MaxPermSize=4096m -Djava.awt.headless=$HEADLESS -cp . Test

The output is expected to be:
java.awt.headless: true
GraphicsEnvironment.isHeadless(): true

Please try.

Best regards,
Jick Yeung

Hi @Jick

As requested, I downloaded the file, unzipped and saved it within the scripts directory. I changed the plugin.sh as shown below:

#!/bin/sh
cd ../bin
if [ "v$HEADLESS" = "v" ]; then
    HEADLESS=true
fi

JAVA="../jre/bin/java"
if [ ! -f "$JAVA" ]; then
    JAVA="../../jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="../../jre.bundle/Contents/Home/jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="../../.install4j/jre.bundle/Contents/Home/jre/bin/java"
fi

if [ ! -f "$JAVA" ]; then
    JAVA="java"
fi

"$JAVA" -Xms4096m -Xmx8192m -XX:MaxPermSize=4096m -Djava.awt.headless=$HEADLESS -cp . Test

Then I run the following command within the terminal:

sh Plugin.sh -project "/Users/admin/Library/Application Support/VisualParadigm/ws/teamwork_client/projects/X/X.vpp"

However it returns the following:

Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Error: Could not find or load main class Test
Caused by: java.lang.ClassNotFoundException: Test

Hi GregS,

Please try to remove “cd …/bin” for the test.

Best regards,
Jick Yeung

Hi @Jick,

After removing the line you mentioned in the previous comment, I now get the following:

java.awt.headless: true
GraphicsEnvironment.isHeadless(): true

This gets returned when I am logged into the device directly and when ssh’ing onto the device too.

Hi GregS,

I’ve passed your reply to our engineering team. When there is a feedback I will let you know.

Best regards,
Jick Yeung

Hi GregS,

It seems that you are running UpdateTeamworkProject.sh but you set headless to plugin.sh

Best regards,
Jick Yeung

Hi @Jick,

Thanks for pointing that out, that seemed to fix the issue! :man_facepalming:

Out of curiosity on the physical device, we have set HEADLESS=false and yet we can still SSH onto the device and run VP without the UI. But on the Mac VM by setting it too true, it works.