how to fix Eclipse losing reference to third party jar in project sets - eclipse

Occasionally I see eclipse lose the reference to the third party jars contained in the a projects. (you get the the build path error stating the jar cannot be found)
Its easy enough to fix as you can remove the jar, save the properties of the project and then go in and re-add the jar that it could not find, eclipse can then see the path to the jar and you can then compile again.
the problem is that if you have a lot of projects in your build you would have to do this task a lot.
Is there anything you can do to force eclipse to recognise that it actually has the jar on its classpath?

I have also faced the similar situation many times with my projects in eclipse. The jar file path is correct in the .classpath file and the jar is present still eclipse do that. To fix it you open the .classpath file and resave it and refresh the probject in eclipse and it builds fine.

That's a weird behaviour...
If that's ok you can use Maven 2 for your projects. This means that you have to follow Maven's project structure, which is quite ok, but it can be a pain if you decide to migrate old projects.
Then you can run mvn eclipse:eclipse whenever you want and that will fix your problem in a few seconds.

Related

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

I’m using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change the version), my Eclipse-Maven project doesn’t pick it up, even when I right click my project, and select “Maven” -> “Update Project.” I know this because I do not see compilation errors in the Eclipse Java editor that I see when I build the project on the command line using
mvn clean install
When I remove the project from the workspace and re-import it, then things get back to normal. However this is a cumbersome process. How do I get my Maven-Eclipse project to automatically detect changes in my pom and update the project libraries appropriately?
And yes, in the “Project” menu, “Build Automatically” is checked.
When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).
So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.
As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:
If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.
Three Mandatory checks you should do for automatic update in your classpath
Your Repository is not in-sync with your Eclipse IDE, Please check the below settings in your IDE.
Right Click your any POM.xml from your IDE and check for the Maven profile which should be auto-activated. Also offline and Force update check box shouldn't be enabled. Please refer the below image.
Always check for your user settings which should reflect your local maven settings.xml, as shown in the below figure.
After performing all these checks, refresh your Eclipse Work-space to get these changes reflected.
Eclipse should be updating your classpath. If it's not, that implies something is going wrong.
It's hard to say what the problem could be exactly without knowing more about your project's pom.xml. More information might be necessary to solve the issue, but I'll just make a stab in the dark:
Open the .project file in your project's root folder and check the ordering of builders and natures there. It might be possible that some other nature on the project is also causing maven2Nature to fail. Move maven nature up and see if that helps any.
Alternatively you might be thinking that Eclipse does not update your dependencies because it does not add some some error indicators in the project that should be there with new dependencies. If that's the case try cleaning the current project (project>clean...). Maven in Eclipse does not necessarily trigger a full rebuild when dependencies are updated.
If none of this works, closing/opening the project might solve the issue quicker than re-importing.
What you wrote, should work. Did you check this:
does "pure" mvn install from terminal see your changes in POM?
maybe some Maybe plugin is buggy, cached some dependencies in target, and mvn clean install is needed
you can run Eclipse in a new workspace, and import your project there, sometimes it helps in case of such strange problems
instead of importing Maven project to Eclipse via m2eclipse, you can try to create Eclipse files via the old mvn eclipse:eclipse and see what happens then
does it work well when you try to import your Maven project to other IDE, the free IntelliJ Community Edition for example?
As a last resort, you can delete your current Eclipse installation and install a new version. When you add several plugins, they might interfere with one another and create weird behavior. After you do that, do not import your Maven project into your workspace, but rather create a new one and copy and paste the files that you had.

Eclipse + JBoss - some JAR files not deployed

I have an Eclipse Indigo installation with a JBoss 6 server managed by it. I have a Maven project with a few modules. These modules all build just fine from the command line.
One of the modules is an EAR. This is dependent on two JAR modules and a couple of WAR modules. When I package the EAR from the command line (mvn clean package), the EAR contains all the necessary JAR and WAR files. However, when I deploy it from Eclipse, the two module JAR files are missing from JBoss. The WAR files are just fine. Inside the "Add and Remove..." dialog the JAR files are also present, but not when deployed. I've checked JBoss' deployments folder and there they are indeed missing. The strange thing is, with the exact same POMs and code, all of my colleagues with the same(?) setup don't have this problem.
The two JAR modules are listed in the dependency management part of the parent POM. They are also listed as dependencies in the EAR POM. Still, Eclipse refuses to deploy them with the EAR.
Does anybody have any idea how I can solve this issue? I can manually package and deploy the EAR, but 1) that takes longer, and 2) I can't use Eclipse's debugging functionality this way.
Note: previously asked at http://www.coderanch.com/t/580959/vc/Eclipse-JBoss-some-JAR-files
Right mouse button on project -> Maven -> Update project
I experienced the exact same issue, different eclipse (Eclipse Mars, WildFly 8.1 ).
The unsettling part was that I didn't change anything in the code or in the IDE (that I am aware of) and it started malfunctioning.
I suspect it has something to do with the cached memory of eclipse for it's plugins, anyway, after many hours of trying different things we fixed it by deleting the folder .eclipse under your user in windows.
Seems silly, but we tried everything except that, and that thing did the trick
I'm encountering a similar issue, however my environment is much, much simpler - being a web project, with a utility project. Not using maven at all and deploying to tomcat7.
The class file is not being deployed to the web-inf as expected, although the utility project is referenced, and marked as to be exported.
However with your issue, I came across this post:
http://blog.frankel.ch/better-maven-integration-leads-to-unforeseen-consequences-bugs#comments
which might provide a clue. Hope this helps.
I had the same issue. I didn't modify my code at all, I deleted all the projects from the work space, closed eclipse and reopened it. Then I did a clean and build of the project (which took much longer than before). This time when I went to add the EAR project, it had all the dependencies listed and actually worked.

How to mark .jar file as excluded from publish/export structure?

I have a .war project in Eclipse. It is probably not relevant but I should mention that it was converted from a maven project using mvn eclipse:eclipse plugin.
I saw a warning that various .jar files on the Build Path were not being exported. To fix this I went to Project Properties -> Deployment Assembly and added the jars that needed to go into the .war
However, one .jar file does not need to go into the .war because it will be provided by the container. It is on the build path merely to get the project to compile.
For this .jar file, I want to get rid of the warning. One way was to Ctrl+1 to QuickFix which caused the Properties->Java Build Path->Libraries tab->...jar file to have an extra line on expanding it which says: Excluded from publish/export structure: (None)
My question is how could I have done this without Quick Fix? I could not find any way to exclude from publish/export structure without using the Eclipse Ctrl+1 Quick Fix.
There is no other UI beyond the quick fix for setting the ignore flag.
m2e-wtp automatically takes care of this for you - any dependency that has the scope as provided is excluded from the publish\export structure.

Trying to include a maven built library in Eclipse, giving missing artifact error

I've seen that there are quite a few questions regarding this problem, but unfortunately none have solved it for me. Here is a screencap of what's going on:
It is dependent on the android-support-v4 jar file which as you can see is added to my build path. It the exact jar file from the maven library directory's libs folder. I've tried the following:
Restarting Eclipse
Cleaning the project
Right-clicking the project and updating dependencies
Updating project configuration Disabling and re-enabling workspace resolution
Nothing has helped. Is there any other tricks to getting this resolved? All of the answer's I've seen suggest doing these things that I have already tried.
Thanks a lot!
Actual root cause:
The OP JMRboosties reports in this instance having to desactivate Proguard (the tool which shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names)
disabling proguard on the line where the error occurred (the <plugin> item) in pom.xml solved the problem
(See "How to use ProGuard with android-maven-plugin ").
Certain side-effects can result from using Proguard: For example, the Proguard page does mention:
The default proguard.cfg file tries to cover general cases, but you might encounter exceptions such as ClassNotFoundException, which happens when ProGuard strips away an entire class that your application calls.
Original answer:
As mentioned in this GitHub post:
you need to use maven Android SDK Deployer to install it:
I'm going to deploy my own android artifacts to my personal repository to avoid having this problem again.
If you're not explicitly using Maven you can just import it as a regular Android project into eclipse and it'll pick up the .jar from the libs/ directory.
(Note your android-support-v4.jar isn't in libs in your project)
declare it in your pom.xml.
You have to install both Android 1.6 and the compat lib using the maven SDK deployer for now.
cd to platforms/platform-4/ and extras/compatibility-v4/ in the deployer and run mvn install in each.
Hopefully the compat lib makes it into maven central soon so I can avoid this step.
Again, the project is set up to be used as a normal Android project in eclipse too completely separate from maven.
File, New, Project, Android, use existing sources, select library/ folder.
Assuming you're using m2e-android behind the scenes, the reason you're getting compile problems is that the m2e-android plug-in strips out all provided scope dependencies from the Eclipse project classpath.
We do this because, due to changes in ADT 16.0.0, any JAR file in the Eclipse classpath will be packaged into distributable APK file.

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)