unix - x windows/X11 question - java

I have a java GUI jar file that i need to launch at my unix terminal. My system admin says "X is already enabled via ssh". But when i type xterm it says
xterm Xt error: Can't open display: xterm: DISPLAY is not set
I did some reading and it says i have to login using
$ssh -X mylogin#xyz
So my question is:
1) What should i do next...i typed xterm again but the window does not launch
2) Suppose i get it working somehow. How can i launch my java GUI. (do i simply type the jar file name)?
Thank you all for your help.

I am assuming you are connecting from your own computer to some server running SSH. First off, you need to install an X11 server on your own machine if you don't have one already. The terminology here is confusing - if you're connecting to another machine by SSH, you're probably used to thinking of your own machine as the client and the remote one as the server. But in the case of X11, those roles are reversed.
Then, you'll need to start X11 on your own machine and within that, launch an xterm. Then from that xterm, you can run ssh -X myserver.example.com and once logged into that remote server, run java -jar myapplication.jar and it ought to work.
The specific mechanism for launching an X Server on your own machine varies by operating system. On Linux/FreeBSD/etc, you're probably running one already. On a Mac, X11 is available under Applications if you've installed the developer tools. On Windows you'll need something like Xming

Go to your unix terminal and do:
export DISPLAY=<ip_addr>:0
For e.g. I would do export DISPLAY=10.18.192.89:0.
The ip-address is of the machine where you want to see the GUI and that machine should have an Xterm client running.

Related

How do I set a X11 Display [duplicate]

I am trying to install a Java application on my Linux machine (Slackware).
I have received the following error, and I do not understand it.
Could you advise me how to approach the problem? Thank you.
Here is what I get: (I see that some X11 DISPLAY variable needs to be set, but what value should I give it and how?)
~$ java -jar gate-5.0-beta1-build3048-installer.jar
- ERROR -
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(Graphic sEnvironment.java:159)
at java.awt.Window.<init>(Window.java:407)
at java.awt.Frame.<init>(Frame.java:402)
at net.sourceforge.mlf.metouia.borders.MetouiaDotsBuf fer.<init>(MetouiaDotsBuffer.java:105)
at net.sourceforge.mlf.metouia.borders.MetouiaDots.<i nit>(MetouiaDots.java:66)
at net.sourceforge.mlf.metouia.borders.MetouiaToolBar Border.<init>(MetouiaToolBarBorder.java:49)
at net.sourceforge.mlf.metouia.MetouiaLookAndFeel.ini tComponentDefaults(MetouiaLookAndFeel.java:241)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefault s(BasicLookAndFeel.java:130)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefault s(MetalLookAndFeel.java:1591)
at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:537)
at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:581)
at com.izforge.izpack.installer.GUIInstaller.loadLook AndFeel(GUIInstaller.java:373)
at com.izforge.izpack.installer.GUIInstaller.<init>(G UIInstaller.java:116)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:30
at com.izforge.izpack.installer.Installer.main(Instal ler.java:62)
If you're on the main display, then
export DISPLAY=:0.0
or if you're using csh or tcsh
setenv DISPLAY :0.0
before running your app.
Actually, I'm surprised it isn't set automatically. Are you trying to start this application from a non-graphic terminal? If not, have you modified the default .profile, .login, .bashrc or .cshrc?
Note that setting the DISPLAY to :0.0 pre-supposes that you're sitting at the main display, as I said, or at least that the main display is logged on to your user id. If it's not logged on, or it's a different userid, this will fail.
If you're coming in from another machine, and you're at the main display of that machine and it's running X, then you can use "ssh -X hostname" to connect to that host, and ssh will forward the X display back. ssh will also make sure that the DISPLAY environment variable is set correctly (providing it isn't being messed with in the various dot files I mentioned above). In a "ssh -X" session, the DISPLAY environment variable will have a value like "localhost:11.0", which will point to the socket that ssh is tunnelling to your local box.
you must enable X11 forwarding in you PuTTy
to do so open PuTTy, go to Connection => SSH => Tunnels and check mark the Enable X11 forwarding
Also sudo to server and export the below variable here IP is your local machine's IP
export DISPLAY=10.75.75.75:0.0
Are you running this from within an X11 environment? You can use a terminal window, but it has to be within X (either after a graphical login, or by running startx).
If you're already within a graphical environment, try export DISPLAY=:0 for bash like shells (bash, sh, etc) or setenv DISPLAY :0 for C shell based shells (csh, tcsh, etc)
If you've connected from another machine via SSH, you use the -X option to display the graphical interface on the machine you're sitting at (provided there's an X server running there (such as xming for windows, and your standard Linux X server).
There are many ways to do this. I did something below convenient to me and always works fine.
On your remote server, make sure to install xorg-x11-xauth, xorg-x11-font-utils, xorg-x11-fonts.
Run the Xming Server on you local desktop
On putty, before ssh to the server, enable the X11 forwarding and set the display location to localhost:0.0
On the server, .Xauthority file is generated and notice that the DISPLAY variable is already set.
$ xauth list
$ xauth add
To test it, type xclock or xeyes
Note: To switch user, copy the .Xauthority file to the home directory of the respective user and also export the DISPLAY variable from that user.
One more thing that might be the problem in a case similar to described - X is not forwarded and $DISPLAY is not set when 'xauth' program is not installed on the remote side. You can see it searches for it when you run "ssh -Xv ip_address", and, if not found, fails, which's not seen unless you turn on verbose mode (a fail IMO). You can usually find 'xauth' in a package with the same name.
Very Easy, Had this same problem then what i did was to download and install an app that would help in displaying then fixed the error.
Download this app xming:
http://sourceforge.net/project/downloading.php?
Install, then use settings on this link:
http://www.geo.mtu.edu/geoschem/docs/putty_install.html or follow this steps:
Installing/Configuring PuTTy and Xming
Once PuTTy and Xming have been downloaded to the PC, install according to their respective instructions.
Configuring Xming
Once Xming is installed, run the application called 'XLaunch' and verify that the settings are as shown:
select Default entries on Display Settings windows, click next
click next on Session Type window.
click next on Additional parameters window(Notice clipboard checkbox is true)
save configuration and click to finish.
Configuring PuTTy
After installing PuTTy, double-click on the PuTTy icon on the desktop and configure as shown:
This shows creating a login profile then saving it.
On ssh -> X11, click on checkbox to enable X11 forwarding.
on X display location textbox, type localhost:0.0
save profile then connect remotely to server to test.
Cheers!!!
For those who are trying to get an X Window application working from Windows from Linux:
What worked for me was to setup xming server on my windows machine, set X11 forwarding option in putty when I connect to the linux host and put in my windows ip address with the display port and then the display variable with my windows IP address:0.0
Dont forget to add the linux hosts IP address to the X0.hosts file to ensure that the xming server accepts traffic from that host. Took me a while to figure that out.
I have had the same issue in Ubuntu 14.04.01 when I tried to install JDK 8 and Netbeans if I launch the script inside a Byobu terminal (maybe with Screens happens the same).
Just exit Byobu and (in a graphical terminal) run the script.
Initial Check.
1) When you are exporting the DISPLAY to other machine, ensure you entered the command xhost + on that machine. This command allows to other machine to export their DISPLAY on this machine. There may be security constraints, just know about it. Need to check ssh -X MachineIP will not require xhost + ?
2) Some times JCONSOLE won't show all its process, since those JVM process may run with different user and you are exporting the DISPLAY with another user. so better follow CD_DIR>sudo ./jconsole
3) In WAS (WEBSPHERE); jconsole won't be able to connect its java server process, that time just go till the link, then try connecting it. This worked for me. May be this page is initializing some variables to enable jconsole to connect with that server.
WAS console > Application servers > server1 > Process definition > Java Virtual Machine
I have faced the same issue with AIX (where command line interface only available, There is no DISPLAY UI) machine. I resolved by installing
NX Client for Windows
Step 1: Through that Windows machine, I connected with unix box where GUI console is available.
Step 2: SSH to the AIX box from that UNIX box.
Step 3: set DISPLAY like "export DISPLAY=UNIXMACHINE:NXClientPORTConnectedMentionedOnTitle"
Step 4: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.
VNC
If you installed VNC on UNIX box where display is available; then Windows and NX Client is not required.
Step 1: Use VNC to connect with Unix box where GUI console is available.
Step 2: SSH to the AIX box from that UNIX box.
Step 3: set DISPLAY like "export DISPLAY=UNIXMACHINE:VNCPORT"
Step 4: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.
ELSE
Step 1: SSH to the AIX box from that UNIX box.
Step 2: set DISPLAY like "export DISPLAY=UNIXMACHINE:VNCPORT"
Step 3: Now if we launch any programs which requires DISPLAY; it will be launched on this UNIX box.
Set the display mode is fine and also make sure that the apache Jmeter start from your USER mode, DON'T run in ROOT user.
$ cd /home/USER/apache-jmeter-5.5/
$ ./jmeter
There are two possibilities for it if your app has GUI or not:
1-) If your java app has GUI, firstly ensure that you have installed jdk package normally (non-headless). For example if you installed this:
sudo apt install openjdk-19-jre-headless
remove it:
sudo apt remove openjdk-19-jre-headless
then install the normal version:
sudo apt install openjdk-19-jre
Simply headless is using for GUIless apps. Further information you can look here: Difference between openjdk-6-jre, openjdk-6-jre-headless, openjdk-6-jre-lib
Then, either try to set DISPLAY variable as:
export DISPLAY=:0
or if it does not work (then, probably you have multiple monitors), set as:
export DISPLAY=:1
then run your jar file:
java -jar gate-5.0-beta1-build3048-installer.jar
2-) If your java app has no GUI, while you are running the app, you can try java.awt.headless=true flag as:
java -Djava.awt.headless=true -jar gate-5.0-beta1-build3048-installer.jar
Don't forget to execute "host +" on your "home" display machine, and when you ssh to the machine you're doing "ssh -x hostname"

How to compile and run a Java program from my Bluehost server

I have some space with bluehost and would like to run a java program that I wrote from it.
The problem is I don't think bluehost supports java. When I ssh in and then type javac -v I get command not found.
Is there anyway to export a java file into something that isn't a .jar that I could run this java program on the bluehost server?
If you want to run a java program on your bluehost server you have a few options.
Option 1. Get dedicated hosting, which probably costs way more, then you can get sudo access and you can sudo yum install java.
If you have dedicated bluehost hosting then:
Login to your Bluehost Control Panel
Click the Server quicklink
Scroll down to the Access Management section.
Click the Primary User tab.
Enable sudo
Option 2. Download java jdk in your local sandbox and install locally.
a. From bluehost terminal run command `uname -m` mine says 64 bit.
b. Go download the 64 bit linux JDK .tar.gz
c. untar it and install it to somewhere local.
d. Add an alias so that javac and java are reachable from terminal.
Option 3. Make your own server or virtual machine.

How can I run a Java GUI application on a headless Linux that does not support GUI?

I have created a Java GUI application that is running in Windows. Now I want it to run it on a headless Linux instance that does not support GUI. I wanted to convert the GUI to TUI. Is there a way I can substitute some classes and make it run in Linux by TUI. Please help.
You can use PeterMmm's suggestion http://www.pitman.co.za/projects/charva/index.html
Or, you can run the GUI on your local machine by running an X server, then connecting to the Linux box using ssh -X. That will show the GUI on your local machine, but the program is actually running on the linux box.
Or, you can run XVFB to fake a GUI on the Linux box. You won't be able to see the GUI or interact with it in any way, but that might not matter to you.
For the sake of spreading a simple and effective solution, I copy the answer provided by #fossfreedom on SA "Ask Ubuntu":
sudo apt-get install xvfb
then:
xvfb :1 -screen 0 800x600x8 &
export DISPLAY=":1"
java application_name.jar
or
xvfb-run -a -e /tmp/some/log/file.log java -jar /home/user/somejava.jar
-> see: https://askubuntu.com/questions/50599/how-do-you-run-a-gui-application-without-gui-gui-application-as-daemon-on-headl
There are some ncurses implementations for Java available like this one: http://www.pitman.co.za/projects/charva/index.html
If you are connecting from another X running Linux machine put following to your user ssh config (~/.ssh/config):
Compression yes
CompressionLevel 9
ForwardX11 yes
ForwardX11Trusted yes
Then when you login to remote Linux machine your GUI going to be forwarded to local screen. Note that it could be slow... notably some AWT applications are really slow even on LAN.
If on Windows, intall CygWin and its Xserver components. Also OpenSSH can be helpful. When you going to connect through CygWin's ssh, use the same config as above. Of course run Xserver prior connecting to remote machine. You also can use Putty to connect to remote, but don't forget to enable X11 forwarding and compression in session config.
Remote machine must have xauth installed + sshd must have X11Forwarding enabled. If OK echo $DISPLAY will show localhost:10.

running java on linux server

I would like to run a jar file extracted from my java project to be run on a Linux server I connect through SSH Tunneling. There are few problems, first there is something wrong with the Display: I get the error
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:173)
at java.awt.Window.<init>(Window.java:437)
at java.awt.Frame.<init>(Frame.java:419)
at java.awt.Frame.<init>(Frame.java:384)
at javax.swing.JFrame.<init>(JFrame.java:174)
at random_v2.v2Frame.<init>(v2Frame.java:127)
at random_v2.Wrapper.main(Wrapper.java:25)
and second is that I am not sure if I have to install other applications as well. In my code, the java program needs to get run other applications like weka, do I have to install weka with the same directory name and specs that is in my mac?
I appreciate your help in advance.
Best wishes
Assuming you're tunneling into this unix box using PuTTY:
Make sure X11 forwarding is enabled in your PuTTY settings.
Connect via command line using this command:
ssh -X user#server
The -X option enables X11 forwarding.

How to run Java programs over ssh?

Let's say I make a Java project in Eclipse that has 3-10 classes and one of which has a main(String[] args) method that starts the whole program and takes 4 arguments at the command line. Let's also say that this project has 6-10 .jar files in src/lib that it needs to run.
If I have ssh access to another computer (UNIX on both ends) and I want to run this program, how exactly do I go about doing so?
I ask because I have been doing some distributed computing projects and I need to run my program on multiple machines but I am a total command line noob and I don't have physical access to all of the machines.
Edit:
Seems I need to SCP the files over. Can someone show me the particular command that makes the Java program run? Including what directory I should run it from and how to include the JAR dependencies.
to run
java -jar thejarfile.jar "arg1" "arg2" "ectect.."
if you want to run it in the background java -jar thejarfile.jar "arg1" "arg2" &
to kill it if its in the background ps -aux to get the id and then kill (id number)
In general, you use ssh to log into a remote computer, and then you run programs from that machine's storage, using that machine's resources.
So if you want to run your Java program on a different machine, you'd need to copy the required files there, then ssh to that machine and run the program from the remote command line.
You write a tiny bootstrap program that will be your MicroKernel. You SCP that MicroKernel to the remote machine. This program will use a custom ClassLoader to pull the rest of the dependencies for your real application down into memory or some storage onto the remote machine. Look into the URL ClassLoader for some help as it can load JAR files from HTTP addresses.
Or you can just zip up your whole program, SCP it to the remote machine, unzip it then run 'java' like normal. If you have SSH access you should have access to scp files onto that machine. If not you can always SSH into the remove machine then scp them from your machine.
Example:
ssh myname#myremotemachine
> mkdir /location/to/program
> scp myname#mydevmachine:/location/to/program/* /location/to/program
This all works really well if you have your SSH keys setup properly and don't have to put in a password.

Categories

Resources