Debug Eclipse SplashScreen without creating a Jar

I have a search all over the Internet, but I could not find the answer to this question:

I need to debug an application that modifies SplashScreen based on the available module.

I know the code:

SplashScreen splash = SplashScreen.getSplashScreen();

It can be used to get an instance when passing:

  • A splash from the command line: java -splash: path / image.gif ClassFile
  • Manifest popup: splashscreen-image: img / SplashNomina.gif

However, when I tried to run the application by passing the -splash value from VM args to Eclipse, it did not work.

Is this possible, since SplashScreen.getSplashScreen () is always NULL. I tried to pass without success:

  • -splash: image.gif
  • -Dsplash = image.gif

Splash api, . , , : (

!

+5
3

, .

SplashScreen-Image: MyGraphic.jpg

, .

Eclipse, VM arg

-splash:MyGraphic.jpg

SplashScreen.getSplashScreen() null.

SplashScreen.getSplashScreen() JDK ( 1,6). . , , . java.awt.SplashScreen. , , , , Eclipse:

public synchronized URL getImageURL() throws IllegalStateException {
    checkVisible();
    if (imageURL == null) {
        try {
            String fileName = _getImageFileName(splashPtr);
            String jarName = _getImageJarName(splashPtr);
            if (fileName != null) {
                if (jarName != null) {
                    imageURL = new URL("jar:"+(new File(jarName).toURL().toString())+"!/"+fileName);
                } else {
                    imageURL = new File(fileName).toURL();
                }
            }
        }
        catch(java.net.MalformedURLException e) {
            // we'll just return null in this case
        }
    }
    return imageURL;
}

, (, , jar) getResource() URL-, CWD. Eclipse , , classpath.

, maven, src/main/resources/MyGraphic.jpg. : i.e.

-splash:src/main/resources/MyGraphic.jpg 

Eclipse (, , )

, , getImageURL getSplashScreen(), .

, Sun/Oracle. classpath - imageURL = getResource ( ), .

, Splash Screen , .

+11

, , , Splash , :

import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class SplashWindow extends JFrame {

  private static final long serialVersionUID = 9090438525613758648L;

  private static SplashWindow instance;

  private boolean paintCalled = false;

  private Image image;

  private SplashWindow(Image image) {
    super();
    this.image = image;
    JLabel label = new JLabel();
    label.setIcon(new ImageIcon(image));
    this.add(label);    
    this.setUndecorated(true);
    this.setAlwaysOnTop(true);
    this.pack();
    this.setLocationRelativeTo(null);

  }

  public static void splash(URL imageURL) {
    if (imageURL != null) {
      splash(Toolkit.getDefaultToolkit().createImage(imageURL));
    }
  }

  public static void splash(Image image) {
    if (instance == null && image != null) {
      instance = new SplashWindow(image);
      instance.setVisible(true);

      if (!EventQueue.isDispatchThread() && Runtime.getRuntime().availableProcessors() == 1) {

        synchronized (instance) {
          while (!instance.paintCalled) {
            try {
              instance.wait();
            } catch (InterruptedException e) {
            }
          }
        }
      }
    }
  }

  @Override
  public void update(Graphics g) {
    paint(g);
  }

  @Override
  public void paint(Graphics g) {
    g.drawImage(image, 0, 0, this);
    if (!paintCalled) {
      paintCalled = true;
      synchronized (this) {
        notifyAll();
      }
    }
  }

  public static void disposeSplash() {
    instance.setVisible(false);
    instance.dispose();
  }
}

, -;)

+3

3 , , . , , .

, VM -splash: image.gif. (not/bin /src ). , , /bin /src ( -splash).

JAR "", , , : " VM, " ( .gif ). , splash, stackoverflow, . - , FatJar. : export > other > fat jar export. " ", MANIFEST.MF, "SplashScreen-Image: splash.gif" ( , , , , ). " dir" ( , , ). .

So, if you want to run using eclipse, add the pop-up image to the root directory and specify -splash: image.gif in the VM arguments. If you want to export the JAR, the FatJar plugin worked for me, as I pointed out.

Hope this helps :)

(sorry for my english, I'm not english: P)

+3
source

All Articles