Programming

No X11 DISPLAY variable was set, but this program performed an operation which requires it. 해결방법

juyeong.lee 2019. 11. 22. 15:11
반응형

Ubuntu에서 .jar 파일을 실행하려고 할 때 위와 같은 에러가 발생했다.

정확하게는 아래와 같은 문구가 출력되었다.

juyeong@DESKTOP-CPOU9NK:~/SicTools$ java -jar out/make/sictools.jar
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Label.<init>(Label.java:150)
        at java.awt.Label.<init>(Label.java:132)
        at sic.sim.views.DataBreakpointView.createView(DataBreakpointView.java:83)
        at sic.sim.views.DataBreakpointView.<init>(DataBreakpointView.java:36)
        at sic.sim.MainView.<init>(MainView.java:63)
        at sic.Sim.main(Sim.java:54)

 

구글링을 열심히 하다가

$ export DISPLAY=:0.0

을 해 보라는 정보를 얻어서 입력했지만

juyeong@DESKTOP-CPOU9NK:~/SicTools$ java -jar out/make/sictools.jar
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:132)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at java.awt.Toolkit$2.run(Toolkit.java:860)
        at java.awt.Toolkit$2.run(Toolkit.java:855)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
        at sun.swing.SwingUtilities2.getSystemMnemonicKeyMask(SwingUtilities2.java:2020)
        at javax.swing.plaf.basic.BasicLookAndFeel.initComponentDefaults(BasicLookAndFeel.java:1158)
        at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:431)
        at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148)
        at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1577)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:539)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:579)
        at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1349)
        at javax.swing.UIManager.initialize(UIManager.java:1459)
        at javax.swing.UIManager.maybeInitialize(UIManager.java:1426)
        at javax.swing.UIManager.getUI(UIManager.java:1006)
        at javax.swing.JPanel.updateUI(JPanel.java:126)
        at javax.swing.JPanel.<init>(JPanel.java:86)
        at javax.swing.JPanel.<init>(JPanel.java:109)
        at javax.swing.JPanel.<init>(JPanel.java:117)
        at sic.sim.views.CPUView.$$$setupUI$$$(CPUView.java:183)
        at sic.sim.views.CPUView.<init>(CPUView.java:172)
        at sic.sim.MainView.<init>(MainView.java:60)
        at sic.Sim.main(Sim.java:54)

다시 에러 발생...

알고보니 DISPLAY=내 컴퓨터의 IP 주소:0.0 으로 입력해야 되는 것이었다.

 

내 컴퓨터의 IP 주소 확인하는 방법 : https://juyeonglee.tistory.com/5

 

 

어쨌든, 해결한 방법은

1. xinit, xterm 설치

$ apt-get update

설치에 앞서 update를 해준다.

$ apt install xinit
$ apt install xterm

2. ~/.profile 파일에 아래와 같은 내용 추가

DISPLAY=컴퓨터IP주소:0.0
export DISPLAY

그러면

$ echo $DISPLAY

명령어를 입력했을 때 값이 제대로 출력되어야 한다.

3. VcXsrv 설치 및 실행

GUI를 실행시켜주는 별도의 프로그램인 VcXsrv 설치가 필요하다.

https://sourceforge.net/projects/vcxsrv/

설치가 완료되면 VcXsrv 실행을 해 준 다음, 원래 입력하려던 명령어를 Ubuntu에서 실행하면 완료!

반응형