Work on a remote project with Eclipse via SSH
Asked Answered
A

9

210

I have the following boxes:

a) A Windows box with Eclipse CDT,
b) A Linux box, accessible for me only via SSH.

Both the compiler and the hardware required to build and run my project is only on machine B.

I'd like to work "transparently" from a Windows box on that project using Eclipse CDT and be able to build, run and debug the project remotely from within the IDE.

How do I set up that:

  • The building will work? Any simpler solutions than writing a local makefile which would rsync the project and then call a remote makefile to initiate the actual build? Does Eclipse managed build have a feature for that?
  • The debugging will work?
  • Preferably - the Eclipse CDT code indexing will work? Do I have to copy all required header files from machine B to machine A and add them to include path manually?
Aforetime answered 18/11, 2010 at 16:0 Comment(9)
Kos, did you end-up using RSE? How was your experience?Retroact
I managed to do it, but: a) CDT had some problems with being aware of the virtual file system (AFAIK this is a temporary issue and will vanish when they rewrite some things to a newer API; maybe they already did? IDK) and b) I had to roll up my own compilation chain (via a custom makefile) and c) an unpleasant annoyance- file save took like 2~3 seconds and this was disturbing.Aforetime
If I'd need to work remotely again today, I'd probably take another spin with RSE, but I might find it more feasible to keep it as a local project and roll up a custom build system, based on e.g. rsync as I've mentioned.Aforetime
And unfortunately- I haven't managed to set up remote debugging or indexing of remote library headers. I doubt that the latter can even be done. The former - I'm positive it can, but I didn't really had the need to dig into it.Aforetime
I access my remote machine by first logging into a login server and then logging from there to my remote machine. Both have different passwords. Is there any way to work on such a remote machine in Eclipse ?Strobotron
@ArjunJRao I'd experiment with opening an SSH tunnel all the way you want to be, and having Eclipse use that tunnelAforetime
@Kos: How can this be done ? COuld you please elaborate ?Strobotron
Here's a git wrapper I wrote in bash to auto-sync a repo from one computer to another. This just answers the question of how to easily develop on one machine in Eclipse while building on another machine. It also assumes the building on the other machine happens from the command-line. stackoverflow.com/questions/4216822/…Bors
Related: How to use Sublime over SSHBors
U
233

Try the Remote System Explorer (RSE). It's a set of plug-ins to do exactly what you want.

RSE may already be included in your current Eclipse installation. To check in Eclipse Indigo go to Window > Open Perspective > Other... and choose Remote System Explorer from the Open Perspective dialog to open the RSE perspective.

To create an SSH remote project from the RSE perspective in Eclipse:

  1. Define a new connection and choose SSH Only from the Select Remote System Type screen in the New Connection dialog.
  2. Enter the connection information then choose Finish.
  3. Connect to the new host. (Assumes SSH keys are already setup.)
  4. Once connected, drill down into the host's Sftp Files, choose a folder and select Create Remote Project from the item's context menu. (Wait as the remote project is created.)

If done correctly, there should now be a new remote project accessible from the Project Explorer and other perspectives within eclipse. With the SSH connection set-up correctly passwords can be made an optional part of the normal SSH authentication process. A remote project with Eclipse via SSH is now created.

Unbidden answered 18/11, 2010 at 16:6 Comment(23)
RSE is still tricky. The best idea from RSE is for Eclipse to do everything over an SSH connection, but that feature isn't yet working. The working feature involves some server which you need to setup on the Linux box.Chemosmosis
If all else fails, modify the project locally. Then install cygwin or mingw so you get "rsync". That allows you to efficiently copy the files over SSH to the remote Linux box. And install Putty to get a remote console. Now you only need to memorize this key-sequence "Ctrl+S Alt-Tab Alt-Tab Up Return Alt-Tab Alt-Tab Up Return" (save in Eclipse, go to the console with "rsync", execute it again, go to putty, run the make command on Linux).Unbidden
Also the RSE guys like to get bug/enhancement reports.Unbidden
@Aaron - I've tried that rsync solution before, from a Makefile - which basically would replace your key sequence with one Ctrl+B. The problem is that with this approach I can neither run nor debug from Eclipse. The RSE indeed sounds like good tool from the job; @Ioan, can you elaborate on what's not working? The RSE wiki seems to list SSH file systems and remote debugging as a current feature... Or I'll just try it out this Monday.Aforetime
If you can get the SSH feature of RSE working, great, I wasn't able to. Best I could do is a complicated mess of Windows shares, batch files, SSH connections, and remote debugging.Chemosmosis
The best thing is that when you re-open eclipse, it takes you right to the directory that you were working in when you last closed. For UTF-8, right click on any file or folder and select properties. In the info tab, change file encoding to "UTF-8". It gets applied to all files and folders for that connection.Hanshansard
is there a way to make this run as root? (like using sudo bash in the command line, only so that it makes the RSE run as root instead of the terminal)?Argal
@Rothschilde: No. As a general rule, never run large applications as root. Create a normal user, develop, test and compile and then use root to deploy.Unbidden
This looks like something that's almost what I am looking for - I too need to run Eclipse from my local Windows installation and use it to develop projects on a remote Linux box. I created a remote project from the RSE perspective, but when I open any of the source files from the Project Explorer, Eclipse throws about a million errors (it doesn't recognize anything except for C++ keywords and function parameters). Least of all, I want to add certain (remote) directories to the project's Paths & Symbols, but all I can choose from is my local machine...Experimentalize
@Argent: I'm guessing here but did you download a version of Eclipse which understands C/C++? Look for "CDE". By default, Eclipse usually only contains support for Java.Unbidden
@AaronDigulla, I did. If I try to create an empty project, for example, the options list C/C++, not Java.Experimentalize
@Argent: Then you should try to ask a question here. Note: Include useful information (like which errors you see, not just "million errors").Unbidden
@AaronDigulla Hi, the solution is cool, but I found that when I'm building the remote project, Eclipse is trying to compile it locally. Is there anyway to let it compile and run in the remote machine?Ina
@shaoyl85: I'm not using the RSE myself; please ask a new question.Unbidden
Can the RSE be used to do this?Idona
Is this stuff still relevant in Sept 2015?Leboff
C/C++ indexing is not working properly with RSE. Indexer complains about missing symbols. It works well when the project and source files are stored locally but with RSE it does'nt. any ideas?Shawm
@Shawm No. Did you check the error log? Maybe they try to execute ctags or similar and the tool isn't installed remotely.Unbidden
@AaronDigulla: How can I check the logs in Eclipse? The only thing I see is a message in RED in the status bar saying "Could not find symbol 'XXXXXYYY' in Index".Shawm
@Shawm Open the view "Error log" help.eclipse.org/mars/…Unbidden
RSE, being its own context, prevents utilizing one of the specialized contexts for your remote project. E.g. I can work remotely with RSE but lose the benefits of the PHP context plugin. :(Fivepenny
Followed it and was able to import the remote project. But how do I get the reference of the remote maven repo libraries?Cornel
IMO this solution is useless without working C/C++ Indexer.Prewitt
A
13

The very simplest way would be to run Eclipse CDT on the Linux Box and use either X11-Forwarding or remote desktop software such as VNC.

This, of course, is only possible when you Eclipse is present on the Linux box and your network connection to the box is sufficiently fast.

The advantage is that, due to everything being local, you won't have synchronization issues, and you don't get any awkward cross-platform issues.

If you have no eclipse on the box, you could thinking of sharing your linux working directory via SMB (or SSHFS) and access it from your windows machine, but that would require quite some setup.

Both would be better than having two copies, especially when it's cross-platform.

Acedia answered 18/11, 2010 at 16:7 Comment(5)
I'm afraid the linux box doesn't even have X11. :)Aforetime
@Kos, you need the X11-server to run where you physically sit - either with a Linux in a virtual machine, or an X11 server for Windows - and Eclipse to run on the Linux server. ssh just allows for tunneling the network data - you will find compression + "-c blowfish" to help the experience.Groove
Just to clarify - are you referring to what's called "headless Eclipse" on the remote machine? (Well, provided it even has Java :)). I was looking for a light client-side solution, but having some setup on the remote machine could be an option too.Aforetime
@Kos: No. X11 works like this: You have a client and a server. The server is where the monitor is connected. It does all the rendering and displaying. The client (Eclipse in this case) just sends rendering commands to the server. So you must install X11 on Windows and run Eclipse on your Linux box. All you need to do on Linux is set the DISPLAY variable so Eclipse knows where the server is.Unbidden
The network needs to be fast though, and so does your server, and or Eclipse will run really slow.Francoise
C
7

I'm in the same spot myself (or was), FWIW I ended up checking out to a samba share on the Linux host and editing that share locally on the Windows machine with notepad++, then I compiled on the Linux box via PuTTY. (We weren't allowed to update the ten y/o versions of the editors on the Linux host and it didn't have Java, so I gave up on X11 forwarding)

Now... I run modern Linux in a VM on my Windows host, add all the tools I want (e.g. CDT) to the VM and then I checkout and build in a chroot jail that closely resembles the RTE.

It's a clunky solution but I thought I'd throw it in to the mix.

Crowboot answered 20/12, 2010 at 9:1 Comment(0)
H
5

My solution is similar to the SAMBA one except using sshfs. Mount my remote server with sshfs, open my makefile project on the remote machine. Go from there.

It seems I can run a GUI frontend to mercurial this way as well.

Building my remote code is as simple as: ssh address remote_make_command

I am looking for a decent way to debug though. Possibly via gdbserver?

Helot answered 22/3, 2011 at 22:34 Comment(0)
M
4

I tried ssh -X but it was unbearably slow.

I also tried RSE, but it didn't even support building the project with a Makefile (I'm being told that this has changed since I posted my answer, but I haven't tried that out)

I read that NX is faster than X11 forwarding, but I couldn't get it to work.

Finally, I found out that my server supports X2Go (the link has install instructions if yours does not). Now I only had to:

  • download and unpack Eclipse on the server,
  • install X2Go on my local machine (sudo apt-get install x2goclient on Ubuntu),
  • configure the connection (host, auto-login with ssh key, choose to run Eclipse).

Everything is just as if I was working on a local machine, including building, debugging, and code indexing. And there are no noticeable lags.

Megohm answered 18/12, 2015 at 12:8 Comment(1)
Just to add this also works extremely well with Windows at the client end. Simple and easy to install both the client and the server, and the experience is just like working locally.Scalpel
M
3

I had the same problem 2 years ago and I solved it in the following way:

1) I build my projects with makefiles, not managed by eclipse 2) I use a SAMBA connection to edit the files inside Eclipse 3) Building the project: Eclipse calles a "local" make with a makefile which opens a SSH connection to the Linux Host. On the SSH command line you can give parameters which are executed on the Linux host. I use for that parameter a makeit.sh shell script which call the "real" make on the linux host. The different targets for building you can give also by parameters from the local makefile --> makeit.sh --> makefile on linux host.

Maillot answered 28/11, 2010 at 16:18 Comment(1)
Nice, but cannot be called "transparent" - doesn't allow debugging at the very least. Also could be based on RSync instead of Samba (which is what I had before I posted my original question).Aforetime
I
1

The way I solved that one was:

For windows:

  1. Export the 'workspace' directory from the Linux machine using samba.
  2. Mount it locally in windows.
  3. Run Eclipse, using the mounted 'workspace' directory as the eclipse workspace.
  4. Import the project you want and work on it.

For Linux:

  1. Mount the 'workspace' directory using sshfs
  2. Run Eclipse.
  3. Run Eclipse, using the mounted 'workspace' directory as the eclipse workspace.
  4. Import the project you want and work on it.

In both cases you can either build and run through Eclipse, or build on the remote machine via ssh.

Icebreaker answered 14/7, 2021 at 15:54 Comment(0)
M
0

For this case you can use ptp eclipse https://eclipse.org/ptp/ for source browsing and building.

You can use this pluging to debug your application

http://marketplace.eclipse.org/content/direct-remote-c-debugging

Morceau answered 11/6, 2015 at 12:17 Comment(0)
B
0

How to edit in Eclipse locally, but use a git-based script I wrote (sync_git_repo_from_pc1_to_pc2.sh) to synchronize and build remotely

This answer currently only applies to using two Linux computers [or maybe works on Mac too?--untested on Mac] (syncing from one to the other) because I wrote this synchronization script in bash. It is simply a wrapper around git, however, so feel free to take it and convert it into a cross-platform Python solution or something if you wish


This doesn't directly answer the OP's question, but it is so close I guarantee it will answer many other peoples' question who land on this page (mine included, actually, as I came here first before writing my own solution), so I'm posting it here anyway.

I want to:

  1. develop code using a powerful IDE like Eclipse on a light-weight Linux computer, then
  2. build that code via ssh on a different, more powerful Linux computer (from the command-line, NOT from inside Eclipse)

Let's call the first computer where I write the code "PC1" (Personal Computer 1), and the 2nd computer where I build the code "PC2". I need a tool to easily synchronize from PC1 to PC2. I tried rsync, but it was insanely slow for large repos and took tons of bandwidth and data.

So, how do I do it? What workflow should I use? If you have this question too, here's the workflow that I decided upon. I wrote a bash script to automate the process by using git to automatically push changes from PC1 to PC2 via a remote repository, such as github. So far it works very well and I'm very pleased with it. It is far far far faster than rsync, more trustworthy in my opinion because each PC maintains a functional git repo, and uses far less bandwidth to do the whole sync, so it's easily doable over a cell phone hot spot without using tons of your data.

Setup:

  1. Install the script on PC1 (this solution assumes ~/bin is in your $PATH):

     git clone https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles.git
     cd eRCaGuy_dotfiles/useful_scripts
     mkdir -p ~/bin
     ln -s "${PWD}/sync_git_repo_from_pc1_to_pc2.sh" ~/bin/sync_git_repo_from_pc1_to_pc2
     cd ..
     cp -i .sync_git_repo ~/.sync_git_repo
    
  2. Now edit the "~/.sync_git_repo" file you just copied above, and update its parameters to fit your case. Here are the parameters it contains:

     # The git repo root directory on PC2 where you are syncing your files TO; this dir must *already exist* 
     # and you must have *already `git clone`d* a copy of your git repo into it!
     # - Do NOT use variables such as `$HOME`. Be explicit instead. This is because the variable expansion will 
     #   happen on the local machine when what we need is the variable expansion from the remote machine. Being 
     #   explicit instead just avoids this problem.
     PC2_GIT_REPO_TARGET_DIR="/home/gabriel/dev/eRCaGuy_dotfiles" # explicitly type this out; don't use variables
    
     PC2_SSH_USERNAME="my_username" # explicitly type this out; don't use variables
     PC2_SSH_HOST="my_hostname"     # explicitly type this out; don't use variables
    
  3. Git clone your repo you want to sync on both PC1 and PC2.

  4. Ensure your ssh keys are all set up to be able to push and pull to the remote repo from both PC1 and PC2. Here's some helpful links:

    1. https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
    2. https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
  5. Ensure your ssh keys are all set up to ssh from PC1 to PC2.

  6. Now cd into any directory within the git repo on PC1, and run:

     sync_git_repo_from_pc1_to_pc2
    
  7. That's it! About 30 seconds later everything will be magically synced from PC1 to PC2, and it will be printing output the whole time to tell you what it's doing and where it's doing it on your disk and on which computer. It's safe too, because it doesn't overwrite or delete anything that is uncommitted. It backs it up first instead! Read more below for how that works.

Here's the process this script uses (ie: what it's actually doing)

  1. From PC1: It checks to see if any uncommitted changes are on PC1. If so, it commits them to a temporary commit on the current branch. It then force pushes them to a remote SYNC branch. Then it uncommits its temporary commit it just did on the local branch, then it puts the local git repo back to exactly how it was by staging any files that were previously staged at the time you called the script. Next, it rsyncs a copy of the script over to PC2, and does an ssh call to tell PC2 to run the script with a special option to just do PC2 stuff.
  2. Here's what PC2 does: it cds into the repo, and checks to see if any local uncommitted changes exist. If so, it creates a new backup branch forked off of the current branch (sample name: my_branch_SYNC_BAK_20200220-0028hrs-15sec <-- notice that's YYYYMMDD-HHMMhrs--SSsec), and commits any uncommitted changes to that branch with a commit message such as DO BACKUP OF ALL UNCOMMITTED CHANGES ON PC2 (TARGET PC/BUILD MACHINE). Now, it checks out the SYNC branch, pulling it from the remote repository if it is not already on the local machine. Then, it fetches the latest changes on the remote repository, and does a hard reset to force the local SYNC repository to match the remote SYNC repository. You might call this a "hard pull". It is safe, however, because we already backed up any uncommitted changes we had locally on PC2, so nothing is lost!
  3. That's it! You now have produced a perfect copy from PC1 to PC2 without even having to ensure clean working directories, as the script handled all of the automatic committing and stuff for you! It is fast and works very well on huge repositories. Now you have an easy mechanism to use any IDE of your choice on one machine while building or testing on another machine, easily, over a wifi hot spot from your cell phone if needed, even if the repository is dozens of gigabytes and you are time and resource-constrained.

Resources:

  1. The whole project: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
  2. See tons more links and references in the source code itself within this project.
  3. How to do a "hard pull", as I call it: How do I force "git pull" to overwrite local files?

Related:

  1. git repository sync between computers, when moving around?
Bors answered 20/2, 2020 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.