Eclipse: change JDK for all projects in Workspace - java

I have received a whole bunch of Eclipse Projects as a ZIP-File. I imported all of them into my new Workspace dedicated for this Task. They are all preconfigured from the other Dev's Workspace. In general I don't mind, so i do not have to setup every one of these Plugin-Projects.
What i do mind is that each and every Project is set to run with a specific JRE from the other guys installation (which I obviously don't have). Is there a convenient Way to change all the Projects in my Workspace to the Workspace default JRE?
I am really not looking forward to right click on every of these ~30 Projects and change it manually.

If they are not Maven or Gradle projects, you can change the .classpath XML files accordingly (<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/..."/>) using a shell/batch or Ant script. Then do a refresh (e.g. by selecting all projects and hitting F5) so that Eclipse is aware of the change.

Related

Moving projects from eclipse workspace

I am using eclipse and I moved some projects(Projects with the name Mc Bot) in my workspace to another folder. However, when I open eclipse with my workspace, projects still appear like this in package explorer.
How can I fix that?
You cannot move project folders on your hard drive and expect Eclipse to update automatically. The folders contain metafiles that Eclipse needs to properly load the workspace on startup.
It is better to either rename/move the projects within Eclipse.
Or to remove and then re-add them to Eclipse's project management.
However, make sure to not accidentally delete the files from disk, when removing the old project from Eclipse. There is a checkbox within the confirmation dialog that - in this case - you should not check.
Especially when you are working with a code versioning system (such as Git or SVN), it is important to rename your files and folders within the code editor. Otherwise your repository might get out of sync.
I would just delete it here in eclipse (don't mark the checkbox to delete on disk) and then reimport it. So in this view from the screenshot just open the context-menu, say import and chose your projects again.

IntelliJ only compiles files once

IntelliJ (Ultimate 2018.1) is not building my project properly. The project is using Maven which doesn't seem to have any problems (all libs are there). The problem is as follows:
Everytime I start up IntelliJ, I am able to build all changes exactly one time. I can change contents of my files and those changes will be contained in the build. But every change I do after that first build is ignored by the build tool. So, every time I build the project (ctrl+f9) after that, I get "All files are up-to-date" and nothing is compiled. (If I am running the app on the application server and try a hot swap, the build says "loaded classes are up to date ...")
Only a restart of the IDE lets me rebuild the project.
Edit: As I just found out, a restart of the IDE is not the only possibility to make a build possible again. In the state of not being able to compile, I changed a setting in the compiler settings. After that, I was able to build again. But only once. I then changed the setting back and well, I could build again. Looks like something odd in the IDE. /Edit
Edit2: Oddly enough, the explicit compiling of the class (ctrl+shift+f9) is working. So the problem circles around the compiling of the whole project. While this is making IntelliJ usable again, it's error prone regarding multiple changed files... /Edit2
A few notes and configurations of the project:
The build produces a .war
It is deployed on a wildfly (which is not started once in this cycle, so this shouldn't be the root of the problem)
The exact same project was formerly developed in Eclipse where building and Hot-Swap worked flawlessly (and still do when I try Eclipse again)
Maven Config:
Compiler config:
Check with Intellij version. As I am using 1.4 community edition and for me its running proper.
Even I have updated few dependencies after building First Time and it get's rebuild automatically.
So for my understanding what you can do it just check with the Intellij update or change the default directory and rebuild it.
The problem with the "Build Project" command is the source discovery of IntelliJ. A long time ago, we made the choice to place our sources inside a folder named ".git" (not the folder in the repository), so IntelliJ had problems to discover the code inside that directory. The reason for that was an old approach of Eclipse to clone repositories into a .git folder. The directory looked like this:
C:\dev\.git\workspace and inside that folder was another .git folder (from the repository).
So, the answer is:
Don't put your git repository in a folder named ".git" or IntelliJ will not compile it (unless you only compile class wise).

Why does Eclipse sometimes rebuild the whole workspace?

I use Eclipse Luna 4.4.0. After I start Eclipse and haven't changed anything it sometimes rebuilds the whole workspace which is sort of annoying. It is not an incremental build, but a full rebuild (which includes cleaning output folders of all projects).
I use autobuild for projects (all java, using svn and git), but autobuild should not lead to this behaviour.
What triggers the complete workspace rebuild? The error log does not contain any hint.
Generally, the builder gets triggered as follows (from the Eclipse wiki).
JDT uses the autobuild facilities provided by the platform. If a resource changes, the platform checks the project description file (see .project in your projects). When the file contains a reference to the Java builder, the builder gets notified of the change and will then compile the Java source file and its dependents.
I don't know what exactly triggers the build on startup (I've always had the feeling that it somewhow "made sense" for Eclipse to do so when starting). Could it be that some of your resources are touched (if you're on a Linux system) during startup?
It also says there on the wiki how to switch off autobuilding (which I guess you're already fully aware of):
autobuild can be turned off through Window > Preferences > General > Workspace > Build automatically.
There are also related bugs on Eclipse's bugzilla, e.g. https://bugs.eclipse.org/bugs/show_bug.cgi?id=73969, https://bugs.eclipse.org/bugs/show_bug.cgi?id=172444.

Set up Eclipse workspace automatically (import projects, target platform and preferences)

I'm trying to set up an Eclipse workspace automatically. So far, I managed to import projects automatically using the Eclipse CDT project and the following command:
eclipsec.exe -nosplash -data workspace -application org.eclipse.cdt.managedbuilder.core.headlessbuild -importAll C:\project
After that command, I can start Eclipse and all projects in C:\project are imported to my workspace.
But how can I import a target platform automatically? And how can I import Eclipse preferences automatically?
I'm unable to find a documentation about the command line arguments of Eclipse CDT. And I it feels strange to install a complete C/C++ tool chain just to import projects (of a Java project). Are there any alternatives?
Thanks and best regards,
Thomas
(I think your question is as old as the universe itself and the answer is at least 10 times more bogous :))
Short Answer: Copy your .metadata folder to the new workspace folder and re-import the necessary projects.
Why:
We have to "clone" and start a new workspace quite often. And I'm pretty sure one of our fellow stackoverflower will suggest you exporting your preferences (which can be done under File/Expert-> type pref and it will be there) However you will soon realize it will not export a whole lot of things. For example projects often times lose their checkstyle prefs or exluded folder prefs. Also prefs like external java compiler or maven repo directory will be lost, not to mention window settings, and so on... the list is long.
But when you copy the whole .metadata directory you keep all that.
Its quite a "barbaric" approach but not failed me yet.
There is a solution called oasp4j-ide available. With this you can have a template workspace with all your preferred settings. This can be used to setup an initial workspace as well as to update existing workspaces and merge the settings without interfering unmanaged user specific settings.
https://github.com/oasp/oasp4j-ide/wiki/features

Eclipse changing workspace and directory

I am not that used to changing workspaces in Eclipse, in fact, I only have one workspace. But right now, there is a need to change workspace and organize different projects but I don't know how to do it.
I saw something about refactoring and simply importing projects but I don't want the outcome of that.
Currently, I have C:\Users\krato\workspace\ as my default workspace and I want to create another in D:\dev\. So I created one using File > Switch workspace > other > D:\dev\. And in that workspace I imported some projects from the prevoius workspace. Yes I already see the projects in the dev workspace but when I open the other workspace (C:) I still see the imported projects and the folder (C:...\workspace) still contains the projects. What I want to do is to transfer the projects in a different workspace and in a different folder, which in my case D:\dev.
I tried to refactor but it says that it overlaps with the workspace location.
Please suggest the best way to do this.
I would also like to ask your recommendations whether I should have a same workspace and projects folder (like what I want to do) or different directories for my workspace and projects folder.
Your project folders don't need to be where your Eclipse workspace is. In fact, I would recommend to keep them separate:
Your project folders contain the project's code, together with Eclipse .project and .classpath files.
Your workspace on the other side contains Eclipse settings for working with your projects. It can contain multiple projects, and a project can be contained in multiple workspaces.
In your example, I would recommend to manually copy or move your code to D:\Dev, create a new workspace in C:\Users\krato, e.g. C:\Users\krato\workspace-dev, and then import your projects there using Import existing projects.
I would recommend moving rather than copying. If you really need a second copy of your project, consider using a version control system such as git and create a branch instead.
To achieve what you want, you need to do the following:
Create a new Eclipse workspace (like you have done already)
Import the projects you want to move using File/Import/General/Existing Projects and select the check box "copy projects into workspace"
Delete the now copied projects from the original workspace in Eclipse and select the check box "delete project contents on disk"
After that you will have completely moved the projects from one workspace to another, including the underlying folders.
I would also like to ask your recommendations whether I should have a same workspace and projects folder(like what I want to do) or different directories for my workspace and projects folder.
It depends on your own preferences and, how the projects are going to be used. I prefer to have my main project folders separate from my workspaces, because some of them will reside on either SVN, GIT or also Dropbox. Especially library projects, that might be used by more than one other projects, are better kept in a separate workspace and/or folder. This allows one to keep the overview and one can simply include these library projects in other workspaces when needed.
If you didn't delete the projects from the first workspace, they will still be there. Did you copy the files from C: to D: or move them? If you copied them to D: and you don't want them on C:, delete them from C:. But make sure they really are on D: first.
Or am I totally misinterpreting your question?
I believe I had a related problem, and conquered it.
I needed to move my entire workspace (containing my project directories) to a different drive, on Windows. If one wanted to move only some projects, and keep the old workspace as well, this could be modified simply by deleting projects as desired.
On http://www.eclipse.org/forums/index.php/t/248863/
nwbeeson had written:
Thank you. Here is exactly how to do this from a friend who is an
Eclipse expert.
1. Open Eclipse and switch to Workspace1 using Switch To Workspace...
2. Check the projects in Workspace1
3. Switch to another workspace to make sure that Workspace1 is closed completely by Eclipse (Critical step!)
4. Quit Eclipse
5. Copy Workspace1 and name the copy Workspace2
6. Copy Workspace2 to a USB flash drive
7. Copy Workspace2 from the USB flash drive onto the hard disk of a different computer
8. Open Eclipse on the new computer
9. Switch to Workspace2 using Switch To Workspace...
The projects open normally from Eclipse on any machine as though that
workspace had been there all along. The critical step seems to be
switching to another workspace before quitting Eclipse. If you skip
that step the copied and transferred workspace does not open
correctly.
This worked perfectly. Without the critical step, Eclipse balked at the new workspace location. All sorts of references to old paths are used, and apparently updated only if the workspace was fully doubly hyperbolically closed prior to the copying of the workspace to a new location.

Categories