Right way of working Java Eclipse project with GIT - java

What's the right way of working with an Eclipse Java project with GIT?
I have the plugin EGIT installed and a simple java project. I did a commit/push of this java project by using the GIT bash console. I pushed only the source files.
Is that correct? Should I use Eclipse IDE somehow to make the init, commit and push? I couldn't find how to do this in Eclipse.
How should I retrieve the project from another machine? Should I use GIT console to retrieve the project or Eclipse?
I did the procedure in several ways, but they failed.

The generic answer is: whatever works for you, works.
We have a large git repository, and users with eclipse and intellij.
Some IDE users use specific plugins, such as Egit, others simply use the "default" support that most IDEs are shipped with. Such users simply go command line, or maybe, some other 3rd party tool.
Me, personally, I only rely on the IDE to show me the history of a file, or sometimes to quickly diff to revisions. Anything else I do on the command line.
From that point of view, as said: anything that works for you, works for you. You can use eclipse to manage the aspects of a git repository, but you don't have to.
Personally, I suggest to first get a good book on git, and to then extensively study the command line tooling. You also seem to be confused between the responsibilities of your IDE, and your source code management system.

Related

how can I import a part of repository as an Eclipse project?

I am (finally) in the progress of migrating a svn repository to git. Transforming the repo itself was not much of a problem, but I cannot make Eclipse play well with the result. (I am kinda new to git, btw).
The repo contains amongst lots(!) of other things a subdirectory with java code which I would like to use in Eclipse as the base directory of a project. The SVN plugin offered a wizard I could use (New > Other > SVN > Checkout Projects from SVN > svn://host/repo/subdir), but the Git plugin does not seem to offer such kind of workflow. Its import only allows for repository roots to be entered.
Is there a way to make git do my bidding
without ripping my repo into subrepositories
without creating some kind of git-svn proxy
by somehow connect the project to the repo after creation?
Does anyone have any ideas?
I am running Eclipse 12/2022, Git Integration 6.4.0, Subclipse 4.3
As you are migrating from SVN to GIT personally I strongly suggest you to change also way of working to use GIT in a more efficient way. So I think that you should consider if it's worth to split it into separate repositories (which is my suggestion).
It's like with a mobile phone and a smartphone. It's hard to change standard mobile phone and replace it with a new smartphone without changing your habits and way how you are going to use it, right? Or similar with migration from Windows to MacOS. It's hard to switch to MacOS and use it like it's a Windows system.
However if you are still stick to SVN way of work please read about sparse-checkout:
https://stackoverflow.com/a/13738951/9983181
https://stackoverflow.com/a/2303645/9983181
and git submodules:
https://git-scm.com/book/en/v2/Git-Tools-Submodules

Setting up Jenkins to build IntelliJ-project (using BitBucket)

I am trying to set up a Jenkins Server to build my IntelliJ-project (using BitBucketfor VCS (git)).
I have been able to set up IntelliJ to build correctly locally, and I am pushing it to bitbucket. I have also managed to set up Jenkins to get the code from BitBucket.
The problems to actually doing the build process itself, my problem being that I can't seem to figure out how to set it up with Ant / Maven, which I have never used before.
Any good suggestions?
PS: I am still searching for tutorials or anything that gives some help towards achieving this, and will be updating if I find something that helps.
Jenkins can fetch the code from the repository to its workspace, but it cannot build it for you. You need to give him the tool to do that. Popular choices are Maven/Ant/Gradle to handle project building for you.
You need to refer to the proper documentation for either Maven or Ant. The process is too broad and project-specific for me to go into details here, but Jenkins provides nice integration for both. If you know neither of them, I think I'd suggest Maven, but it's up to personal preferences and project needs.
You should first try to build project locally. Once you acomplish that, doing that with Jenkins shouldn't be a problem.

Java project from existing ant build file doesn't appear as in version control

I have a repository in which I have a simple ant project (only the src directory and the build.xml file). I did a checkout of this project in a local copy. Then I opened Eclipse, created a "Java Project from existing Ant build file" and it worked fine. I can build, clean, run, generate javadocs, etc. However, my problem is that the source files in the packages, as well as the project itself, doesn't appear to be under version control in Eclipse. I can work with it fine from Cygwin, but not from the GUI.
The odd thing is that I have several regular Java projects, on the same repository which are synced fine by Eclipse, so it's not a version issue.
When I created the projects that work, I had to go to Team->Share Project... and Eclipse told me that they were already under version control and updated its configuration. However, in this current case, this isn't working. Any suggestion please?
EDIT:
I'm using svn 1.8.
UPDATE: I tried creating a regular Java project, and this time the version control looks fine, so it appears it's an issue related only to Java Project from Existing Ant build file.
The problem is that Eclipse doesn't know your project is using Subversion as a version control tool. You did a checkout outside of Eclipse, then you set up Eclipse as if this was a non-version controlled project.
To get Eclipse to recognize the project as under Subversion, you need to let Eclipse know. This means you should have said "File->New->Project, and select SVN->Checkout Project from SVN in the new project wizard. Then, Eclipse would have checked the project out in Subversion for you, and Eclipse would understand this project is in Subversion.
Unfortunately, I am not quite familiar enough with Eclipse to know how to tell Eclipse that the current project is really under version control. The best I could come up with was:
Right-click on the project and select Team->Share
Say this is a Subversion project you want to share.
Select the Repository to use
Select the folder where you want this project, and select the current folder.
You get the following warning:
Warning: The specified folder already exists in the repository. If you continue, that folder will be checked out to the existing location. Do you want to continue?
Your project will now be "checked out" over your current project. Everything should be okay because the files you have either match what is in Subversion or are modified versions of what is in Subversion.
You will be then asked to use the Synchronized view. Check "Yes", and then switch back to the Java view. Eclipse will now know your project is under Subversion and everything should work fine.
Note the use of Shoulds and Coulds. This is my way of saying that the advise given is done on an "as is" basis and I am not responsible for any damage done by following this advice, so please don't sue me.
It's basically your standard open source license.

How to see full compile path in Eclipse?

I have looked for an answer for this nearly every where that I can think of, but there doesn't seem to be any way to actually SEE what Eclipse "runs" to compile the projects (as it does need the JDK installed and visible to actually build). I ask because I imported a few jars into my project, and even though I've looked through all the javac documentation, I can't seem to figure out how to mimic it quite like Eclipse does. I really, really need to be able to compile on the command line in this case - Eclipse or any other IDE just isn't what is needed.
I started to look through the Eclipse source, and although this sounds lazy, I just became overwhelmed and figured I would ask here first, hoping someone else had the same question at one point.
Eclipse JDT does not require the JDK and does not use javac - it uses it's own compiler.
You can see the classpath by reading your project .classpath file. The various builders that are used to perform build operations (Java, or whatever the project builds) are listed in the .project file. (These are also listed in the project settings.)
It is possible to invoke Eclipse to build your project in headless mode, or write Ant scripts that can be executed both with the JDK and within Eclipse, or install Maven support for internal and external building. It is also possible to configure the project builders to rely only on external tools.
Look at these two articles.
http://www.eclipse.org/articles/Article-Builders/builders.html
http://www.eclipsepluginsite.com/builders-natures-markers.html
Look at your .classpath file and start building an ANT build.xml. You need to do this to be able to have consistent builds on a build machine anyways. It is unlikely that a build server would have eclipse installed on it anyways.
Maven is also another tool that is used for builds. In our shop we use Ant.
Have a look at ant4eclipse - this project allows for generating the appropriate ant data structures for invoking <javac> from the .classpath files and a projectSet.psf file.
By using this we can use Eclipse "natively" and bend ant to conform to Eclipse. The usual approach is the other way around.

Getting a lightweight installation of Java Eclipse

Having dealt with yet another stupid eclipse problem, I want to try to get the lightest, most minimal Eclipse installation as possible.
To be clear, I use eclipse for two things:
Editing Java
Debugging Java
Everything else I do through Emacs/Zsh (editing JSP/XML/JS, file management, SVN check-in, etc). I have not found any aspect of working in Eclipse to do these tasks to be efficient or even reliable, so I do not want plug-ins that relate to it.
From the eclipse.org site, this is the lightest install of eclipse that they have, and I don't want any of those things (Bugzilla, Mylyn, CVS xml_ui), and have actually had problems with each of them even though I do not use them.
So what is the minimal build I can get that will:
Ignore SVN metadata
Includes the full-featured editor (intellisense and type-finding)
Includes the full-featured debugger (standard Eclipse/JDK)
Does not have any extra plug-ins, platforms, or "integrations" with other platforms, specifically, I don't want to deal with plug-ins relating to:
Maven, JSP Validation, Javascript editing or validation, CVS or SVN, Mylyn, Spring or Hibernate "natures", app servers like a bundled Tomcat/GlassFish/etc, J2EE tools, or anything of the like.
I do primarily Spring/Hibernate/web-mvc apps, and have never dealt with an Eclipse plug-in that handles any of it gracefully, I can work effectively with my own toolset, but Eclipse extensions do nothing but get in the way.
I have worked with plain eclipse up to Ganymede, MyEclipse (up to 7.5), and the latest version of Spring-SourceTools, and find that they are all saddled with buggy useless plug-ins (though the combination is always different).
Switching to NetBeans/Intellij is not an option, and my teammates work with SVN-controlled .class/.project files, so it pretty much has to be Eclipse.
Does anyone have any good advice on how I can save a few grey hairs?
You can download the empty Eclipse platform and then manually install the JDT tools.
Go to the The Eclipse Project Downloads page.
Choose the bundle you want, probably Latest Release.
On the download page of the chosen bundle:
Download Platform Runtime Binary
Download JDT Runtime Binary
Extract the Platform Runtime Binary archive file and run it (for example, by double clicking on eclipse.exe).
Install the JDT binary:
Click Help → Install New Software → Add... → Archive.
Choose the JDT zip file you downloaded.
Uncheck Group Items by category.
Select the Eclipse Java Development Tools.
Click next to install and restart Eclipse when prompted.
JDT from the Eclipse update site
You can also install JDT from the Eclipse update site, instead of downloading the binary.
To do this, do this following:
Skip downloading the JDT Runtime Binary, only download, extract and run the Platform Runtime Binary.
Go to the Install New Software, but instead of Archive chose the Eclipse download site.
Search and install Eclipse Java Development Tools.
The "Eclipse IDE for Java Developers" version isn't the smallest one! Look for "Eclipse Classic" - it doesn't contain most of the things you mentioned. It's larger in download size only, because it comes with source code.
See this comparison: http://www.eclipse.org/downloads/compare.php
You can use a thirdparty distribution builder like Yoxos and download just what you want.
A bit late to this party, but I asked myself the same question for a while, and while now I'm back to a more fully-fledged Eclipse installation, I used to to the following to streamline it a bit. Hope it helps.
What I Needed
Functionalities:
Java Support
Java + Java EE (XML) + Debug Perspectives
Pretty much it. There's a lot of other things I like to use in Eclipse, but I needed to keep it down to the skinniest possible because I was in a 3GB environment where I also needed to run other servers in parallel, so I couldn't afford much.
Resulting Perspectives:
Lightweight Java
Lightweight Browser (fairly tweaked for code reviews and code inspection - that one was actually heavier than the others)
Lightweight Debug
What I Did
Install Eclipse Java EE (install classic if not caring about the Java EE/XML bits)
disable hungry views
disable outline (when you need one, just do CTRL+O)
disable call and type hierarchies
disable decorators
disable menu entries (right-
disable toolbar items
even better: hide the toolbar
disable hovers and actions associated with that
disable spell-checking
disable XML validation
disable Mylyn
disable non-needed search forms in CTRL+H dialog (I usually actually only use the "File Search" mode, sometimes the "Java" one)
disable usage reporting
disable unnecessary plugins or features
disables perspectives and plugins loaded automatically on startup
restrict internal limits:
some views have a scope (enclosing class, project, working set, workspace...)
some views and UI elements have boundaries (console/loggers, highlighters, markers...)
tweak the eclipse.ini to:
-clean the workspace (slower, but I tend to prefer to do that)
use G1GC
reduce memory usage (I noticed that I can perfectly live with -xss128k and -xmx384 with G1, for instance. YMMV, of course, as always with JVM tuning.)
use a server VM (and point directly to the VM's DLL)
Also disable views you don't need in the "Debug" and "Code Browsing" perspectives.
Sorry, I had actually saved all of these as a set of 3 lightweight perspectives to re-import everytime on my new project, but I cannot get my hands on them at the moment. If I ever find then, I'll add a link to them here.
Instead of going for a ready package from Eclipse Downloads, from the same page go for the Eclipse Installer. Currently available for Mac, Windows & the beloved Linux. Launch the Installer which should update (or not if you are lucky enough :) ). Select "Eclipse Platform" which is the absolute minimum from this IDE, set your other installation preferences and install.
After the download/installation process, I'd suggest your head to Help->Install New Software and search for the Eclipse Marketplace (Yes, even that is not included in this package) just to make your life a bit easier.
Get as minimal an installation as you can, and then remove whatever is left that you don't want.
Longer answer:
I played around a bit. Here's how I experimented:
Extract a clean eclipse*.zip to two different directories; call it eclipse and eclipse-bak. We'll only modify eclipse.
Before starting it the first time, remove some of the features from the features folder. I got rid of org.eclipse.cvs, org.eclipse.epp.\*, ...mylyn\*, ...wst\*.
Start up Eclipse to a workspace. Create in that workspace a Java project, debugging configuration, etc. Stuff that you would want to do and that will complain if we remove the wrong thing. Open up the Error Log view.
Close Eclipse. Remove something (or a group of things) from the plugins folder.
Open Eclipse. Check the error log to see if something you care about couldn't load. If it did, add those things back from eclipse-bak/plugins. If not, close Eclipse and return to step 4 for a new set of plugins.
Using this I got my configuration to still be able to edit and debug Java files, but including only these plugins:
com.ibm.icu*
org.apache.*
org.eclipse.compare*
org.eclipse.core*
org.eclipse.debug*
org.eclipse.draw2d*
org.eclipse.ecf*
org.eclipse.epp.package.java*
org.eclipse.equinox*
org.eclipse.help*
org.eclipse.jdt*
org.eclipse.jface*
org.eclipse.ltk*
org.eclipse.osgi*
org.eclipse.platform*
org.eclipse.rcp*
org.eclipse.search*
org.eclipse.team.core
org.eclipse.team.ui
org.eclipse.text
org.eclipse.ui*
org.eclipse.update*
org.hamcrest*
org.sat4j*
Most of that is core stuff, but you might be able to trim it down further. Notably gone are Mylyn, the usage collector, EMF, CVS, WST, even JUnit (though I think you should keep JUnit).
I feel you man, when working with Eclipse, the application is constantly trying to help.
Ignoring workspace corruptions, I spend my development time fighting all the "helpful" things Eclipse does.
XML is not that hard to read, but it still confuses the shit out of me when I get the XML designer.
All it does for me is add an extra manual step to click on the source tab.
Every time a new version of eclipse comes out they redesign the front page and the distributions.
At which time a new quest starts for finding a way to debloat Eclipse again.
I have the same experience with extensions to Eclipse by third parties and avoid them if at all possible.
WTP has somewhat usefull stuff, but overall I prefer a basic java eclipse.
It is a good idea start with the Platform Runtime Binary and add JDT.
Manually extracting the JDT runtime doesn't seem to work for me these days, so it it better to use the update client.
You can use the marketplace client, but personally I have always found it rather annoying.
An alternative is to use the director. The director can install JDT without starting the GUI.
Here is a script that downloads eclipse Oxygen 4.7.3a and installs JDT unnattended:
#!/bin/sh
die() {
echo >&2 "$#"
exit 1
}
[ "$#" -eq 1 ] || die "exactly 1 argument required [INSTALL_DIR]"
[ -e "$1" ] && die "*warning* Aborting! location exists, eclipse already installed?"
INSTALL_DIR="$1"
TARBALL=eclipse-platform-4.7.3a-linux-gtk-x86_64.tar.gz
mkdir -p $INSTALL_DIR
if [ ! -f $TARBALL ]
then
wget http://mirror.csclub.uwaterloo.ca/eclipse/eclipse/downloads/drops4/R-4.7.3a-201803300640/$TARBALL
fi
tar -v -xf "$TARBALL" -C "$INSTALL_DIR" --strip 1
echo "\nUsing director to install java development tools, this may take a while..."
$INSTALL_DIR/eclipse -noSplash -application org.eclipse.equinox.p2.director -repository http://download.eclipse.org/eclipse/updates/4.7 -installIUs org.eclipse.jdt.feature.group
Simply call the script with one argument, the directory you want Eclipse installed.
Running the script gives me an unpacked install of roughly 129MB, which is more than 100MB smaller than the default download (zipped).
That is not to say you would not be able to shrink it further, but it should rid you of most of the crap.
The executable will be cached for future executions of the script, but it will still be slow, since it needs to go online to download JDT.
Unfortunately, I do not know of a way to cache the plugin download in a local folder.
You could of course zip the created installation, but the script is easier to commit to git.
This script will only work for new users as long as the mirror stays up and will need some updates when a new version is released.
But I am sure most developers are savvy enough to update the script if need be.
If you only want to use Eclipse for editing / Debugging Java I would suggest using a plain Text editor. It seems an overkill to install Eclipse and not use most of its features.
A very popular choice is VIM. Also check out this SO link for tips in using VIM as a Java editor. You can also debug Java code with a command line debugger as mentioned in this SO link.
I have figured out how to get the lightest possible eclipse with minimal efforts(imo). For the reference this is what I want in my eclipse:
Java project with Maven support
JavaEE support(Servers)
Debugging of Java application
(Irrespective of these you can install any feature that comes with Eclipse IDE with minimal effort, just follow the guide below)
Here's how I get it:
Go to eclipse download packages (Here's the link)
Find MORE DOWNLOADS (right hand side) and go to Other builds (Here's the link)
Now go to any build you like (Usually Latest Downloads -> whatever the first Build Name. Also There is links for older versions and archive site)
Under Platform Runtime Binary you can download Eclipse Platform as per your OS and/or requirement.
Now extract the archive and run the eclipse
Go to Help -> Install New Software...
Using Work with you can install your desired plugins and tools which usually ships with bulky eclipse
In Work with drop down select the site(mostly first) similar like this 2022-03 - https://download.eclipse.org/releases/2022-03 here 2022-03 is my eclipse version you may see different depending your version.
Now you can select the group(s) or expand the group(s) and select the specific plugins which you need and also you can filter by name like maven, debug, server, marketplace client etc in filter text input just below the Work with drop-down menu.
Install plugins and enjoy your very own lightweight eclipse.
Visual Studio Code
Fast forward to 2019 and we now can use Visual Studio Code with Java plugins. They provide a plugin pack to get you started with lightweight debugger and auto complete. Other plugins include maven integration, dependency viewer and more.
Visual Studio Code is a new(ish) editor/mini-ide from Microsoft which runs on Win/Max/Linux and has plugins for many languages.
Tutorial for setup: https://blog.usejournal.com/visual-studio-code-for-java-the-ultimate-guide-2019-8de7d2b59902
Edit 2019-06-21: MS now has a dedicated installer for Java integration with VS Code, including Spring Boot support as well. While the Intelisense is not 100%, it's vastly improved and now my go-to Java editor for testing and trying new things. Announcing the Visual Studio Code Installer for Java

Categories

Resources