JSmooth generated exe does not show Splash Screen

蓝咒 提交于 2019-12-23 05:11:28

问题


I wrap my Java Swing application as an exe using Jsmooth but I can see no way to take advantage of Java 6 splash screen option. I have the following manifest file:

     Manifest-Version: 1.0

     SplashScreen-Image: resources/LOADLOGO.png

     Main-Class: se.bookingapp.UI.MainFrame

The splash screen appears if I simply click on the jar file of the application. However, the JSmooth generated exe form of the jar file does not show the splash screen somehow. Does anyone know why?


回答1:


Does it work when you execute the jar file? Open it with WinRar for example, and check if the manifest is into META-INF folder, and LOADLOGO.png is in the right folder too.

After doing that, it should work. It works for me. Nothing wrong in your manifest.




回答2:


Yesterday I've finished to develop my java application and I had the same issue. If I double click the .jar file or I execute in a command line splash screen works perfectly, but when I execute the wrapped file it doesn't. Seems just JSmooth doesn't support this feature.

However I made a little trick to have a wrapped .exe and splash screen working at the same time. I made a little application called ApplicationLoader.jar that consists in a single main class that execute java -jar "Application.jar" in a command line. Here is the complete code:

public class ApplicationLoader {
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {        
    /* First I check if the first parameter is not null and it's not an empty string */
    if(args[0] != null && !args[0].trim().isEmpty()){
        /* Then I use java.util.regex package to validate the parameter is a .jar file */
        Pattern pattern = Pattern.compile(".*jar");
        Matcher matcher = pattern.matcher(args[0]);            
        if(matcher.matches()){
            /* Finally I define the command line like: java -jar "Application.jar" */
            String command = "java -jar \"" + args[0] + "\"";
            try {
                Runtime r = Runtime.getRuntime();
                ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", command);
                Process p = pb.start();
                p.waitFor();
                } catch (IOException | InterruptedException ex) {
                   JOptionPane.showMessageDialog(null, ex.getMessage(), "Error executing: "+command, JOptionPane.ERROR_MESSAGE);
                }                
        } else {
            JOptionPane.showMessageDialog(null, "The argument is not a .jar file!!");
        }            
    } else {
        JOptionPane.showMessageDialog(null, "There's not a valid argument!");
    }
}
}

I have this folder structure for my application:

MyApp
  +-- bin
  |    +-- MyApp.jar
  |    +-- ApplicationLoader.jar
  +-- MyApp.exe

So in JSmoot I changed the classpath to ApplicationLoader.jar and add the relative location to my application in Application Arguments section like this:

And that's it. I know this is not the best option but is a workaround.

However there's a little problem:

Since ApplicationLoader.jar calls a cmd.exe then the wrapped .exe and your application will execute in two different processes.

This implies that if you have to kill .exe process for some reason (unexpected crash or something), your java application still working as a java.exe process. So in that case you must kill MyApp.exe and java.exe processes. Actually if you just kill java.exe process then MyApp.exe process will finish execution by itself.

If you keep this in mind and you can live with that I think this option is quite simple and useful. I hope this be helpful to anybody looking for a workaround to this issue.



来源:https://stackoverflow.com/questions/8114572/jsmooth-generated-exe-does-not-show-splash-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!