通过 SSH 使用 Eclipse 处理远程项目

发布于 2024-10-03 08:21:02 字数 421 浏览 0 评论 0 原文

我有以下盒子:

a) 带有 Eclipse CDT 的 Windows 盒子,
b) 一个 Linux 盒子,我只能通过 SSH 访问。

构建和运行我的项目所需的编译器和硬件都只在机器 B 上。

我希望使用 Eclipse CDT 从 Windows 机器上“透明地”工作该项目,并能够远程构建、运行和调试该项目从 IDE 中。

我该如何设置:

  • 建筑物能够正常工作?有什么比编写本地 makefile 来 rsync 项目然后调用远程 makefile 来启动实际构建更简单的解决方案吗? Eclipse 托管构建有这方面的功能吗?
  • 调试能用吗?
  • 最好 - Eclipse CDT 代码索引可以工作吗?我是否必须将所有必需的头文件从机器 B 复制到机器 A 并手动将它们添加到包含路径?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

情深如许 2024-10-10 08:21:02

尝试远程系统资源管理器 (RSE)。它是一组插件,可以完全满足您的需求。

RSE 可能已包含在您当前的 Eclipse 安装中。要检查 Eclipse Indigo,请转到窗口 > 开放的视角 > 其他...,然后从打开透视图对话框中选择远程系统资源管理器以打开 RSE 透视图。

要在 Eclipse 中从 RSE 角度创建 SSH 远程项目,请执行以下操作:

  1. 定义新连接并从“新建连接”对话框的“选择远程系统类型”屏幕中选择“仅 SSH”。
  2. 输入连接信息,然后选择完成。
  3. 连接到新主机。 (假设已设置 SSH 密钥。)
  4. 连接后,深入查看主机的 Sftp 文件,选择一个文件夹,然后从项目的上下文菜单中选择创建远程项目。 (等待远程项目创建完毕。)

如果操作正确,现在应该有一个新的远程项目,可以从 Project Explorer 和 Eclipse 中的其他透视图访问。正确设置 SSH 连接后,密码可以成为正常 SSH 身份验证过程的可选部分。现在通过 SSH 使用 Eclipse 创建了一个远程项目。

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.

脱离于你 2024-10-10 08:21:02

最简单的方法是在 Linux Box 上运行 Eclipse CDT 并使用 X11-Forwarding 或远程桌面软件(例如 VNC)。

当然,只有当 Linux 机器上有 Eclipse 并且与机器的网络连接足够快时,这才有可能。

优点是,由于一切都是本地的,因此您不会遇到同步问题,也不会遇到任何尴尬的跨平台问题。

如果你的盒子上没有 Eclipse,你可以考虑通过 SMB(或 SSHFS)共享你的 Linux 工作目录并从你的 Windows 机器访问它,但这需要相当多的设置。

两者都比拥有两个副本更好,尤其是在跨平台时。

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.

野鹿林 2024-10-10 08:21:02

我自己(或曾经)处于同一位置,FWIW 最终检查了 Linux 主机上的 samba 共享,并使用 notepad++ 在 Windows 计算机上本地编辑该共享,然后通过 PuTTY 在 Linux 机器上进行编译。 (我们不允许在 Linux 主机上更新编辑器的十个版本,而且它没有 Java,所以我放弃了 X11 转发)

现在......我在我的虚拟机中运行现代 Linux Windows 主机,将我想要的所有工具(例如 CDT)添加到 VM,然后签出并构建与 RTE 非常相似的 chroot 监狱。

这是一个笨重的解决方案,但我想我应该将其加入其中。

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.

命硬 2024-10-10 08:21:02

我的解决方案与 SAMBA 类似,只是使用 sshfs。使用 sshfs 挂载我的远程服务器,在远程计算机上打开我的 makefile 项目。从那里出发。

看来我也可以通过这种方式运行 Mercurial 的 GUI 前端。

构建我的远程代码就像这样简单: ssh 地址remote_make_command

不过,我正在寻找一种不错的调试方法。可能通过 gdbserver 吗?

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?

尛丟丟 2024-10-10 08:21:02

我尝试了 ssh -X 但速度慢得难以忍受。

我也尝试过 RSE,但它甚至不支持使用 Makefile 构建项目(我被告知自从我发布了我的答案,但我还没有尝试过)

我读到 NX 比 X11 转发更快,但我无法让它工作。

最后,我发现我的服务器支持 X2Go (链接有安装说明如果你的没有)。现在我只需要:

  • 在服务器上下载并解压 Eclipse,
  • 在本地计算机上安装 X2Go(Ubuntu 上的 sudo apt-get install x2goclient ),
  • 配置连接(主机,使用 ssh 密钥自动登录 ) ,选择运行 Eclipse)。

一切都就像我在本地机器上工作一样,包括构建、调试和代码索引。并且没有明显的滞后。

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.

半岛未凉 2024-10-10 08:21:02

两年前我遇到了同样的问题,我通过以下方式解决了它:

1)我使用 makefile 构建我的项目,而不是由 eclipse 管理
2) 我使用 SAMBA 连接来编辑 Eclipse 内的文件
3)构建项目:
Eclipse 使用打开 SSH 连接的 makefile 调用“本地”make
到 Linux 主机。在 SSH 命令行上,您可以给出参数
都是在Linux主机上执行的。我使用 makeit.sh shell 脚本作为该参数
它调用 Linux 主机上的“真正的”make。
您还可以通过参数给出不同的构建目标
本地 makefile --> makeit.sh --> Linux 主机上的 makefile。

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.

森末i 2024-10-10 08:21:02

我解决这个问题的方法是:

对于 Windows:

  1. 使用 samba 从 Linux 计算机导出“工作空间”目录。
  2. 在 Windows 本地安装它。
  3. 运行 Eclipse,使用安装的“工作空间”目录作为 Eclipse 工作空间。
  4. 导入您想要的项目并对其进行处理。

对于 Linux:

  1. 使用 sshfs 挂载“工作区”目录
  2. 运行 Eclipse。
  3. 运行 Eclipse,使用安装的“工作空间”目录作为 Eclipse 工作空间。
  4. 导入您想要的项目并对其进行处理。

在这两种情况下,您都可以通过 Eclipse 构建和运行,或者通过 ssh 在远程计算机上构建。

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.

忘东忘西忘不掉你 2024-10-10 08:21:02

对于这种情况,您可以使用 ptp eclipse https://eclipse.org/ptp/ 进行源代码浏览和构建。

您可以使用此插件来调试应用程序

http://marketplace.eclipse.org/内容/直接远程-c-调试

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

梦幻的味道 2024-10-10 08:21:02

如何在 Eclipse 中进行本地编辑,但使用我编写的基于 git 的脚本 (sync_git_repo_from_pc1_to_pc2.sh) 进行同步和构建< /em> 远程执行

此答案目前仅适用于使用两台 Linux 计算机 [或者也可能在 Mac 上工作? - 未经 Mac 测试](从一台同步到另一个)因为我在 bash 中编写了这个同步脚本。然而,它只是 git 的包装器,所以请随意将其转换为跨平台的 Python 解决方案或其他东西(如果您愿意的话)。


这并不能直接回答 OP 的问题问题,但它是如此接近,我保证它会回答许多其他登陆此页面的人的问题(实际上包括我的问题,因为我在编写自己的解决方案之前首先来到这里),所以我'无论如何我把它发布在这里。

我想要:

  1. 在轻量级 Linux 计算机上使用强大的 IDE(如 Eclipse)开发代码,然后
  2. 通过 ssh 在不同的、更强大的 Linux 计算机上构建该代码(从命令行,而不是从 Eclipse 内部)

让我们调用第一个我在其中编写代码“PC1”(个人计算机1)的计算机,以及在其中构建代码“PC2”的第二台计算机。我需要一个工具来轻松从 PC1 同步到 PC2。我尝试了 rsync,但对于大型存储库而言,它的速度非常慢,并且占用了大量的带宽和数据。

那么,我该怎么做呢?我应该使用什么工作流程?如果您也有这个问题,这是我决定的工作流程。我编写了一个 bash 脚本来自动化该过程,使用 git 通过远程存储库(例如 github)自动将更改从 PC1 推送到 PC2。到目前为止,它运行得很好,我对此非常满意。 它比 rsync 快得多,在我看来更值得信赖,因为每台 PC 都维护一个功能性的 git 存储库,并且使用更少的带宽来完成整个同步,因此可以轻松地通过手机热点,无需使用大量数据。

设置:

  1. 在 PC1 上安装脚本(此解决方案假设 ~/bin 位于您的 $PATH 中):

     git 克隆 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
     光盘 ..
     cp -i .sync_git_repo ~/.sync_git_repo
    
  2. 现在编辑您刚刚在上面复制的“~/.sync_git_repo”文件,并更新其参数以适合您的情况。以下是它包含的参数:

     # PC2 上您将文件同步到的 git repo 根目录;该目录必须*已经存在* 
     # 并且你必须*已经`git clone`d*了你的git repo的副本!
     # - 不要使用诸如`$HOME`之类的变量。相反,要明确一点。这是因为变量扩展将 
     # 当我们需要来自远程计算机的变量扩展时,发生在本地计算机上。存在 
     # 显式反而可以避免这个问题。
     PC2_GIT_REPO_TARGET_DIR="/home/gabriel/dev/eRCaGuy_dotfiles" # 显式键入此内容;不要使用变量
    
     PC2_SSH_USERNAME="my_username" # 明确键入此内容;不要使用变量
     PC2_SSH_HOST="my_hostname" # 显式键入此内容;不要使用变量
    
  3. Git 克隆您想要在 PC1 和 PC2 上同步的存储库。

  4. 确保您的 ssh 密钥已全部设置为能够从 PC1 和 PC2 推送和拉取远程存储库。以下是一些有用的链接:

    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/generate-a-new-ssh-key-and-adding-it-to-the-ssh -代理
  5. 确保您的 ssh 密钥已全部设置为从 PC1 到 PC2 的 ssh .

  6. 现在 cd 进入 PC1 上 git 存储库中的任意目录,然后运行:

    sync_git_repo_from_pc1_to_pc2
    
  7. 就是这样!大约 30 秒后,所有内容都会神奇地从 PC1 同步到 PC2,并且它会一直打印输出,告诉您它正在做什么以及它在磁盘上的哪个位置以及哪台计算机上执行操作。它也很安全,因为它不会覆盖或删除任何未提交的内容。相反,它首先支持它!请阅读下面的更多内容,了解其工作原理。

以下是该脚本使用的流程(即:它实际执行的操作)

  1. 从 PC1:它检查 PC1 上是否有任何未提交的更改。如果是这样,它将它们提交到当前分支上的临时提交。然后它强制将它们推送到远程 SYNC 分支。然后,它取消刚刚在本地分支上执行的临时提交,然后通过暂存您调用脚本时之前暂存的任何文件,将本地 git 存储库恢复到原来的状态。接下来,它将脚本的副本rsync发送到 PC2,并执行 ssh 调用来告诉 PC2 使用特殊选项来运行脚本,只执行 PC2 的操作。
  2. PC2 的作用如下:它cd进入存储库,并检查是否存在任何本地未提交的更改。如果是这样,它会创建一个从当前分支分叉出来的新备份分支(示例名称:my_branch_SYNC_BAK_20200220-0028hrs-15sec <-- 请注意,这是 YYYYMMDD-HHMMhrs--SSsec),并提交任何未提交的更改到该分支并带有提交消息,例如在 PC2(目标 PC/构建机器)上备份所有未提交的更改。现在,它会检查 SYNC 分支,如果本地计算机上尚不存在该分支,则将其从远程存储库中拉出。然后,它获取远程存储库上的最新更改,并执行硬重置以强制本地 SYNC 存储库与远程 SYNC 存储库匹配。您可以将此称为“硬拉”。不过,它是安全的,因为我们已经在 PC2 上备份了本地所有未提交的更改,因此不会丢失任何内容!
  3. 就是这样!您现在已经生成了从 PC1 到 PC2 的完美副本,甚至无需确保干净的工作目录,因为脚本会为您处理所有自动提交和其他内容!它速度很快,并且在大型存储库上运行得很好。 现在,您有一个简单的机制,可以在一台计算机上使用您选择的任何 IDE,同时在另一台计算机上构建或测试,如果需要,可以通过手机的 WiFi 热点轻松地进行构建或测试,即使存储库有数十 GB,您的时间和资源都受到限制。

资源:

  1. 整个项目:https ://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
  2. 在该项目的源代码本身中查看更多链接和参考。
  3. 如何进行“硬拉”,我称之为:如何强制“git pull”覆盖本地文件?

相关:

  1. 移动时计算机之间的 git 存储库同步?

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?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文