Eclipse not seeing my updated classes - java

explored all solutions to this, including clearing out metadata folder and making sure the compiler matches the project version. I also have build automatically checked.
When I save my files in eclipse they update in the filesystem, but when I attempt to run my maven project and deploy it to the JBoss server it runs and old version.
I've even put in compiler errors on purpose and it doesn't bother it at all.

Please try building your project with a clean command
mvn clean install
and also refresh your workspace in eclispe. Might help!

do maven clean install through eclipse maven plugin, to avoid different code base confusion, it seems you are editing some different code base on eclipse which is different when you build through maven.
recheck the path for both the cases.
At the end copy the jar from the eclipse project itself after refresh the project on eclipse.
I faced the same issue, due to eclipse was not loading the new jar, caching the old one. it's required to refresh the project on eclipse before taking the build jar.

Related

Eclipse and Gradle classpath out of sync: cannot be resolved to a type

We are having a frustrating problem with our Eclipse workspace. Here is a high-level example of what is happening:
ProjectA
-- src/main/java/...
-- build.gradle
ProjectB
-- src/main/java/...
-- build.gradle
After running gradle eclipse and importing the projects into Eclipse, we occasionally will get 'MyType cannot be resolved to a type' even though the following are true:
Our projects have the Gradle library container on their classpath
The projects have the correct workspace projects within their Gradle container
Things like CTRL + Click work from types that are showing up with red underline (i.e. compile error) meaning Eclipse knows exactly how to get to those types, but the compiler can't find them
Command-line Gradle builds work as expected
This is happening throughout the team and we cannot figure out why Eclipse keeps going out of sync and cannot compile from time to time. What usually fixes the problem is a combination of:
Project > Clean in Eclipse
Gradle cleanEclipse or gradle eclipse
Reimporting the projects
etc
Other notes:
Using Gradle version 2.2.1
Happens in both Eclipse Luna and Eclipse Mars
Using JDK 8
Has anyone else had these types of compile issues in Eclipse with Gradle projects?
One source of such problems can be letting Gradle generate the Eclipse project metadata/setup files (what you get by running gradle eclipse). I know that the Maven and Gradle teams really want their tool (Maven or Gradle) to generate that stuff, but they notoriously do a less-than-ideal job of it. For example, the last time I used Gradle it configured the .classpath to use a hard-coded JRE library path instead of the preferred Execution Environment. That kind of poor job of generating files makes for developer headaches.
Instead, the Eclipse recommendation is to manually configure your projects (for the most part), only letting Gradle manage its Classpath Container, then checking in the Eclipse .project, .classpath, and .settings files/folders in to your SCM (svn, git, etc.). That way, the process of checking out a project into a workspace is automatic and does not require running gradle eclipse or mvn eclipse:eclipse all the time.
That's the way that Eclipse projects were originally designed and intended to be managed, and it works very well. I've worked with setups like that on very large projects (100+ separate projects in Eclipse and dozens of developers). It also cuts down on the number of steps to go from zero to running app.
This is one of those philosophical differences between Maven/Gradle and Eclipse; when it comes down to it, IMO, the IDE should manage it's stuff and the build/dependency tool should just stay out of the way.
Try manually getting things just right in your project configuration and then checking in those files - see if it doesn't relieve the headaches your team faces in this area.

How to download all possible maven dependencies so they are local

I work behind a very massive firewall that likes to hiccup on random connections, which makes all work with remote repositories a living nightmare for me!
I am looking to work with a project from Git (this one https://github.com/mrniko/netty-socketio) which heavily utilizes maven for downloading dependencies.
What I would like to do is on another terminal (such as http://cloud9.io or something) download all the maven dependencies so that the entire project can be run standalone.
I have already tried mvn clean install and then zipping up the source folder, but its actually not enough! I still get ClassNotFound related errors when I try to run the project locally in eclipse. And for the record, I did add the compiled *.class files in the build properties, so Eclipse knows where they are. It seems like there are some random classes that get generated dynamically which still aren't present (such as log4j -- and I really don't want to hunt each one down individually)
I am wondering if there is a fully thorough way to download all possible dependencies from maven and then either run a project 100% standalone, or create a local maven server from it?
I am running Java 7 on Eclipse Luna and I do have Maven installed on my windows 7 machine (though again it barely works on remote repositories). I also have a Cloud9 instance which I could use to run Maven commands, then zip up the results for local download.
When you execute mvn clean install, maven downloads all dependencies of currently built project to your local maven repository. This is usually located in
%USERPROFILE%\.m2\repository
When you build your project, maven uses that path, to lookup required dependencies.
If you want do download them all, you can try using mvn dependency:copy-dependencies. Then, you'll find all project dependencies intarget/dependencies directory of your project. This also includes transitive dependencies.
To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin. Using that plugin, you can generate eclipse .project and .classpath files, using mvn eclipse:eclipse command. This will populate eclipse files with required dependencies from maven. You should then import the project to eclipse using Import existing projects into workspace, instead of Import existing maven projects.
maven-eclipse-plugin will add all those jars relative to a folder specified by M2_REPO variable. Just make sure you edit this variable inside eclipse project properties, and you should be set.
I've had to deal with similar issues. I would find that due to changes in firewall policies, occasionally all the .jar files in my project had been updated to be a 1K file that, when opened within notepad++ contained a message from the firewall saying that the download had been blocked.
I recommend looking into Nexus for your local repository management, it means your local projects don't have to go past your firewalls to check for maven updates.
http://www.andrejkoelewijn.com/blog/2010/03/09/getting-started-with-nexus-maven-repository-manager/
Use dependency plugin go-offline task.

m2e Does Not Detect Any Jars in Local Repository

In my Java project, which has a maven 'nature', m2e version 1.0.10020110804 does NOT detect any jars located in my local repo. I can successfully compile/install using maven from the command line, but when I open the project in Eclipse I'm notified of 100+ (cannot be resolved to a type) errors. Does anyone know how to resolve this problem? I've tried updating dependencies and cleaning my project, but neither works. My local repo is set in m2e under 'User Settings'.
M2e needs to be configured to use your local , home repository . In general, one would expect it to do so automatically... But in your case, its using a different home repository.
I feel your pain here - I have seen it use a default repo inside of eclipse in some cases, which can cause problems if you have / need your own local .m2 directory.
I believe that when I first got this problem, I was installing the m2e plugin without having installed first setting maven up as a standalone application. In this case, it might be that the m2e plugin uses a local maven copy/repo .
So the moral of the story is : You need to configure the plugin to "see" and "use" your M2_HOME correctly.
There are some good tips on getting the settings right here : Eclipse m2eclipse getting dependancies from local repository
By editing the m2e plugin settings through the Preferences window, you can ensure that m2e is accessing the right Maven HOME directory, and that will solve this problem.
I recently faced the same problem. The root cause was that I imported my project as a generic project and later added maven and java natures to it. I resolved the issue by closing and removing the project from my workspace and re-importing as a maven project and then syncing it with my local repo. HTH.
did you try refreshing the workspace?
I am having a similar experience, and I've tried all those thing because it wasn't recognizing the Rhino jar in my unit tests. A lot less errors, but still a couple. Had to close the project, close eclipse, run mvn clean compile, open eclipse, open the project.

Maven project worked before "clean install". Why?

I have two maven projects and both are working fine independently. I am able to create a jar file and run it from console as well as from eclipse.
I copied over some classes from the second project into the first and made a few changes so that it runs as a single project with features from both.
I have two pom files, so I combined them into a single pom file.
The thing is that I am able to run it from eclipse fine and able to get the output I was hoping for.
But I am not able to run it after executing the jar file created from "mvn package".
I am using shade maven plugin.
If I use maven build.. with clean install as goal, it again showing errors.
My question is this, why this discrepancy?
We would need more information to correctly diagnose the issue. One thing to look at is to ensure that any changes to dependencies which are projects in Eclipse have been installed as a command line build will only look in your repo, not at your Eclipse project.
This may happen when you have a dependency which exists as an open project in your eclipse workspace.
Try closing every project except the one where you're having this problem. Does it still compile in eclipse then?

Eclipse IDE behaves weirdly

I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)

Categories