Wrestling with Eclipse-modified .classpath in a Mixed Windows/Mac Team Environment - eclipse

I'm using Eclipse on a small development environment where one developer has a Windows PC and the other has a MacBook. We share code using a subversion repository, and use Maven as an "External Tool" (not using the m2e plugin).
We each have an M2_REPO variable that has been working great for resolving paths to .jar files on our two systems. Recently, however, I ran a command to tell Maven to pull down sources and javadocs.
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
Since then, I see some very Windows-centric references in my .classpath that are a nuissance to my Mac-using friend.
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4.jar"
sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/John/.m2/repository/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
Even after having removed the downloadSources and downloadJavadocs parameters, and verified that they're false in my plugin configuration for maven-eclipse-plugin, deleted my .classpath file, and reran mvn eclipse:eclipse I still see those unwanted references placed into my .classpath file.
Has anyone found a good working solution to this problem? Have I overlooked some setting that tells Maven to use the M2_REPO variable in its references to javadoc files?

On my team we don't commit Eclipse .settings or .classpath files into source control. When we initially check out projects we use m2e to build the classpath (did it with eclipse goal as you are once upon a time) and everything is set up correctly no matter what platform the developer is using. We have people using Win 7, Macs, and various Linux flavors and the build machine is Linux, no issues I know of anywhere.

I don't use maven, I am the only developer and I have a Windows PC and a Mac. For me this "small" solution works fine. Create a symbolik link so your paths on both systems match:
C:\> mklink /d "C:\Users\xxx\android-sdks" "C:\Users\xxx\AppData\Local\Android\android-sdk"
I did this on the windows machine. The command is mklink /d (for directory) newDir existingDir. Works on Windows 7 at least. Maybe this will help.

Try enabling the dependency management of your maven project by:
Right Click on the project –> Maven –> Enable Dependency Management
After this delete and recreate your .classpath file.

Rather than use 'mvn eclipse:eclipse', install M2Eclipse either from the project site or through the Eclipse Marketplace. It will handle all the linkups for you, and not embed absolute paths.
(I always version .classpath and .settings/)

If you have javadocs in your repository, the maven eclipse plugin will always add them to your classpath.
The -DdownloadJavadocs=true option only tells the eclipse plugin to download them. It does not tell the plugin to include them or not in your classpath. If you do not want them in your classpath anymore, you have to remove all -javadoc. from your local repository (or delete your locate repository).

Related

pom.xml marks "Missing artifact com.sun:tools:jar:1.8.0"

I am trying to develop with Eclipse 2020.6 and m2e using openJDK-11 on Win10.
The computer is maintained by IT department having jre-8 in its PATH and I dot have the rights to change that.
I have installed JDK11 below my user folder.
Changed eclipse.ini for Eclipse and toolchain.xml for commandline Maven.
I also checked Module Dependencies in Java Build Path: com.sun.tools.jar is no longer there.
Commandline Maven and Eclipse are using JDK11 instead of jre-8, except the eclipse-editor for pom.xml.
It shows Missing artifact com.sun:tools:jar:1.8.0
I checked Dependency Hierarchie with the pom.xml editor and it shows that ant:1.10.8 depends on tools:1.8.0. But this information must be wrong, as the project tests and installs correctly.
I guess, the eclipse-editor for pom.xml somehow does not use the java libaries pointed to by eclipse.ini or toolchain.xml or those configured with the project Build Path.
Eclipse Preferences/Maven/User Settings points to the local repository .m2\repository and to the user settings .m2\settings.xml. I also copied toolchain.xml to .m2, but without solving the problem.
Please note that I do not have any problem running Maven from within Eclipse. It works as expected. My problem is, that errors are flagged within Eclipse where there is none.
Why does the pom.xml editor in Eclipse complains about tools.jar:1.8.0? How can I make m2e not using java from the PATH but using JDK11 installation for my developments in Eclipse?

How to add maven repository jars to eclipse buildpath?

From eclipse I can see all the necessary jars in maven repositories view. But I have around 100 errors for the missing jar files. So I have set M2_REPO environment variable. I have ran the mvn eclipse:eclipse command from command line. When I run this command an ear package is added to one of subpackages of my project. For example my project name is portal. And sub package is portal_ear. The ear after running mvn eclipse:eclipse command is added to target folder of portal_ear. So my question is as I have the jars already in the repository, how can I add those to the portal buildpath inside eclipse?
Thanks.
When you're using M2Eclipse, all you need to do is to make sure your Eclipse project is a Maven project. Select the project, click on "Convert > Convert to Maven project" or "Maven > Enable dependency management".
Do not manually add libraries. Also, the M2_REPO library variable is no longer used with m2eclipse, neither is to run the "mvn eclipse:eclipse" command. That is legacy you don't need to do any more.
You can also import your project by using "File > Import > Maven > Existing Maven project" and M2Eclipse will correctly set up the project's build path.
If you have custom Maven settings, such as an Enterprise Repository, you may want to tell M2Eclipse where to find your settings.xml file, if you do not have it in your user home but in the Maven installation (people do this sometimes). Go to "Window > Preferences > Maven > User Settings" and choose the right settings.xml.
Install m2e from the eclipse marketplace. You can now import existing maven projects into your workspace or convert existing ones.
Works very well for Eclipse 3.7
In my case, I had an existing project that was deployed in Eclipse fine. Thank you Mkyong: http://www.mkyong.com/spring-security/spring-security-hello-world-example/
But when I needed to add JSTL for Logout tag support, I didn't see how to add the the jstl.jar file that was just pulled into my repo as another M2_REPO/xyz configuration. Instead, I could only import it as you would a regular .jar file - and that didn't seem right to me.
After reading a bunch of posts without success, I decided to see if I could get around the Eclipse UI and update the project configuration manually. From the project I opened .classpath in a text editor and added a new entry for the jar file:
<classpathentry kind="var" path="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2.jar" sourcepath="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
Then I just refreshed my project in Eclipse (no restart required) and ...
the JSTL build error I was having in my JSP page went away
the build path entry for JSTL was appearing with the same M2_REPO as the other entries
the deployed code worked fine in Tomcat
Yes a bit of a hack, but still relatively clean I think - cheers
Right click on the project --> Maven --> Update Project...
For me it worked simply like that

Where can I obtain the maven-source-plugin?

I checked out an open-source project from SourceForge's SVN source control using the Eclipse Maven plugin. After it checks out, I get this error in the pom.xml file:
Error resolving version for plugin
'org.apache.maven.plugins:maven-source-plugin' from the repositories
[local (C:\Documents and Settings\thomas.owens\.m2\repository),
central (http://repo1.maven.org/maven2)]: Plugin not found in any
plugin repository
I'm fairly new to Maven, but I followed the installation instructions for Apache Maven and the Eclipse plugin. It seems weird that this plugin would not be found in the central plugin repository for Maven or my local repository, when I can clearly see a directory located at C:\Documents and Settings\thomas.owens\.m2\repository\org\apache\maven\plugins\maven-source-plugin that contains a single resolver-status.properties file.
Any thoughts as to why this plugin might not be found and where I can find it?
The problem that I was encountering was not an issue with the maven-source-plugin, but incorrect proxy settings that was preventing the connection to the repositories. The answers to this question on the use of Maven with a proxy helped me to find the mistake and correct it.
That plugin is in the central repository.
Perhaps you just need to run with -U to update:
mvn -U clean install
Or in Eclipse: right-click on the project, select Maven-> Update Dependencies, (perhaps) Maven-> Update Project Configuration
Check if you are able to see Maven in Eclipse, Window > Preferences.
If so, select Maven and go to installations and check if the folder, in where maven was installed, is properly set. Then, set your setting.xml file, it should be in /(maven installation folder)/conf/
Then, right click in your project go to Maven > Update Maven Dependencies.
Did it help?
Which project?
Perhaps there is a bug in their pom.
Or perhaps they require a 'standardized' develop environment with specific environment variables set, or a specific setting in user.home/.m2/settings.xml

Extract eclipse project .classpath dependencies into ant script

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.
As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.
The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.
Any ideas on how Eclipse project dependencies could used in an ant script?
Right click on your Project -> Export
"General/Ant Buildfiles".
Choose the projects and there you go.
Otherwise...
I have some experience with ant4eclipse and it is a hassle to get it stable.
Go check Buckminster or Maven Tycho for a good solution.
I'm currently using Ivy along with Ant, Eclipse and Maven.
I just love the way Ivy works.
Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.
We were looking for a way to manage our dependencies a lot better than how we were doing it.
So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant.
Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.
I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.
Hope this helped
If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.
Depending on if you are in a plugin project and dependencies you might need to add the
${eclipse_home}.
In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.
I believe the ant4eclipse project provides support for executing Ant builds based on Eclipse metadata files.
However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.
This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xml files to transform these into Eclipse .classpath files. Thus the Ant build.xml files were the single configuration point for our projects.

Changing Eclipse project to use Maven?

My boss asked me to convert one of our projects to use Maven to build. So I created a pom.xml file and now Maven builds the project fine and runs all the tests and everything. "Fine", my boss said, "We don't need these any more" and he deleted the /libs directory from the project, and he deleted the JRE from the classpath. That's fine, it still builds in Maven, but Eclipse shows everything that was in the jre or in /libs as unresolved in the editor. Because of all the error indications, I'm seriously considering going back to vi. How can I get it so Eclipse can do its thing?
To create the Eclipse .classpath and .project files, do the following:
mvn eclipse:eclipse
This will create references to your local Maven repository, which means that you'll have to build at least once with Maven, so that it can download the files. I believe you also have to define an Eclipse classpath variable M2_REPO (at least, I have one defined, and can't see any other reason I'd have done that).
I'll assume your boss deleted the JRE entry from the Eclipse classpath, which was dumb but not as dumb as deleting your actual JRE directory. The Maven-build classpath file should include something appropriate, or you can go into the "Build Path" dialog and add the JRE via the "Libraries" tab.
Oh never mind - I clicked the "Maven->Enable dependency management" and that fixed it. Don't know why I didn't think of it before.
Use a Maven-Eclipse plugin.
http://mevenide.codehaus.org/
http://m2eclipse.sonatype.org/
You can use plugins as Nick mentions, but you can also solve this very simply by pointing eclipse to your local maven repository.
1) create a classpath variable, M2_REPO, in your workspace. It should point to something like "c:\Document and Settings\yourname.m2repo\
2) Add the jars that you need.
These steps can also be automated with mvn eclipse:eclipse goal as well. The docs are here, I used it in the past but had some difficulties customizing it (for WTP and Spring configuration files under /.settings/ folder in the project)