Override install4j UnixLauncher WM_CLASS property - java

Is it possible to override the WM_CLASS set by install4j on Linux environments?
At the moment, executing
xprop WM_CLASS
on my application deployed with install4j always returns com-install4j-runtime-launcher-UnixLauncher.
This is a problem when creating proper .desktop files, I do not want to group together all applications deployed with install4j.
I gather this question deals with a similar problem. However, the answer does not work for me. The mentioned sys.ext.windowClass compiler variable is not documented anywhere I can find and as far as I can see it does nothing.

On Linux, window managers group windows and assign the correct icons by using the WM_CLASS property.
This property can be inspected using xprop:
xprop WM_CLASS
To specify which WM_CLASS a .desktop file should affect, you can use the StartupWMClass property in a desktop file:
StartupWMClass=<my-applications-wm-class>
The problem with install4j is that all deployed applications will use
com-install4j-runtime-launcher-UnixLauncher as WM_CLASS.
As Ingo Kegel mentions in his now edited answer to this question, this can be circumvented by setting the WM_CLASS window property explicitly in your Java application using the following code:
String wmClass = ...;
Toolkit toolkit = Toolkit.getDefaultToolkit();
Class<?> toolkitClass = toolkit.getClass();
if (Objects.equals("sun.awt.X11.XToolkit", toolkitClass.getName())) {
Field awtAppClassName = toolkitClass.getDeclaredField("awtAppClassName");
awtAppClassName.setAccessible(true);
awtAppClassName.set(null, wmClass);
}
If you have preliminary dialogs when your application starts (e.g. for selecting a workspace), it is important that you do this for all dialogs separately.

Related

How to use global arguments for Java in vscode?

I am trying to setup my JavaFX enviroment so I referenced the corresponding Jars. In order to run the code I need to use some VM Arguments
("vmArgs": " --module-path /Users/adrif/Downloads/javafx-sdk-14.0.2.1/lib --add-modules javafx.controls,javafx.fxml")
in the launch.json. I am working in a multi-project folder so every time a make a new one I have to go to the launch.json and add the arguments. How do I set global arguments? I found adding arguments in "launch" at user settings.json (Launch - Global debug launch configuration. Should be used as an alternative to 'launch.json' that is shared across workspaces)
but doesn't work as I expected.
As you can see, I have two JavaFX projects under the package JavaFX.
And every time I run a new project I have to add the vmArg line to each project.
This is the "launch" options but as I said, it doesn't work or there's someting wrong with how I'm trying to do it. So as the title sais, how to I set global arguments?
Edit : I found the "java.jdt.ls.vmargs" option which allows to specify extre VM Arguments. I does not work either.
Solved, turns out it was fixed in newer versions of Vscode and it's pertinent Java Extensions. The workaround that I used was just adding a new set of arguments for every file in the project.
"vmArgs" was JVM related, "java.jdt.ls.vmargs" was java language server related, the language server was contained in the "Language Support for Java(TM) by Red Hat" extension, so it will not work.
The "launch" configuration in settings.json I tried in local and does not work too.
VSCode has not provided this feature for the present, You need to configure the "vmArgs" for each project. This is because the launch.json file contains different language debugging settings, and lots of configuration was exclusive to some language.

How to attach a javaagent to all java applets

I wrote a sample java agent that creates a "hello world" file in a specific place. I want it to run whenever any java applet is run (definitely including ones I didn't write myself.) How do I do that?
My agent works when I run it manually from the command line (as in, running another java file with the agent attached to it.) On the automatic front, I tried going into the java configuration panel -> Java -> View -> JRE Configuration Settings -> setting the optional arguments to attach my agent, but that doesn't seem to do the trick. I browse with FF to someplace that makes me run a java applet but no file is created.
I'm guessing I'm missing something basic here, because when I try to google this people all around various forums seem to answer it as if it's the most trivial thing: "just use -javaagent, read more about it in this (link)."
If it helps at all, this is the optional parameter I add in the configuration panel (which works when I use it manually):
-javaagent:C:\Users\admin\workspace\poc\bin\poc\myagent.jar
Update: I found out I can set an environment variable (JAVA_TOOL_OPTIONS) to -javaagent:(agentpath). Once again it works flawlessly with local java applications, but now when I browse over to a webpage with an applet, firefox auto-closes itself. IE declares the webpage broken. Chrome doesn't even display the applet. The agent itself at this point does nothing - it just has an empty premain method. Anyone?
Setting the environment variable JAVA_TOOLS_OPTIONS=-javagent:(path) is right.
My error was that I misconstructed the .jar file. Once I fixed that (simply used the jar.exe tool to make my .jar) it worked properly - locally and on all applets via firefox. Until then, that was what caused firefox to either hang or crash when encountering an applet.

How to get IE or applets to revert back to using old version of installed JRE?

I installed JRE 6 on my existing 1.4.2 causing some applets in IE6 requiring 1.4.2 to stop working, how can i revert this back without uninstalling JRE6?
How do you deploy your applet? I assume you are using a jnlp file descriptor (Java Web Start).
If so, maybe you find this link useful:
http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/syntax.html
You can use this advice when deploying:
http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
As far as I know, the standard in deploying applets nowadays is to use the deployJava script AND a jnlp file. This way you can detect the client's jre's using
getJREs()
Choose the appropriate one and then initiate your applet by calling:
runApplet(attributes, parameters, minimumVersion)
Please take in account that depending on the Java Plugin the client runs, above approach might not work. DeployJava gives you an option to handle that
To deploy an applet that runs on the old and new Java Plug-ins,
specify the applet tag attributes and JNLP parameters as shown in the
example below:
var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D',
code:'java2d.Java2DemoApplet.class', archive:'Java2Demo.jar', width:710, height:540} ;
var parameters = {fontSize:16, jnlp_href:'java2d.jnlp'} ;
var version = '1.6' ;
deployJava.runApplet(attributes, parameters, version);
On windows, go into control panel, select the java icon, click on the java tab and then on the view button. This should show you a list of installed runtimes, enable and disable whichever you need.

Setting Java Swing application name on Mac

I'm writing a Java Swing application for the Mac using Java 1.6. I've read a number of tutorials that step you through how to better integrate your Java application with OS X, but there's one thing I haven't been able to get working. I can't get the application name (the first, bolded menu item in the Mac menu bar) to display. By default, the fully-qualified class name of the main class is shown and I can't get it to change.
This site says that you have to set the following property:
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");
But that doesn't work (I'm running 10.6, so maybe the property name changed?).
When I create a new Java project in XCode (I normally use Eclipse), the name somehow magically gets set! (it starts you out with a runnable, boiler-plate application) I've looked all around the XCode project for how this is done, but I can't figure it out!
My guess is that it only sets the application name if you wrap your Java application up in a Mac *.app package, but was wondering if anyone knew the answer. Thanks.
EDIT: Interestingly, it sets the application name if I package my application in a runnable JAR file, but not if I run it from Eclipse.
You should do the following during app initialization, before GUI is built:
// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");
// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");
// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UPDATE.
Above code works in Java 1.5, this code may not work in 1.6
For new java see documentation:
Either use -Xdock:name command-line property: -Xdock:name=YourAppName
Or set CFBundleName in information property list file (plist)
On Mac 10.7.5, programatically setting the property will work with with Java 1.6 but not with Java 1.7.

<ProjectName.ProjectUI sucks as a name for my Netbeans java OS X app

What property in Netbeans to I need to change to set the name of my java swing app in the OS X menubar and dock? I found info.plist, but changing #PROJECTNAMEASIDENTIFIEER# in multiple keys here had no effect.
Thanks,
hating netbeans.
The answer depends on how you run your application. If you run it from the command line, use '-Xdock:name=appname' in the JVM arguments. See the section "More tinkering with the menu bar" in the article linked to by Dan Dyer.
If you are making a bundled, double-clickable application, however, you just need to set the standard CFBundle-related keys in your application's Info.plist (see the documentation on Info.plist keys for more details).
Check:
nbproject/project.properties
nbproject/project.xml
in project.xml look for the name element...
But... Why not just select the main project and right click and do rename?
This is not NetBeans-specific, but this article has some useful tips about tweaking your Swing apps so that they fit in on OS X.

Categories