I have been all over existing posts that deal with the ClassNotFoundException running a Java web app under Tomcat in Eclipse.
I am unable to provide source code and configuration artifacts because I am working on a proprietary code base. However, through trial and error I have boiled the problem down to its basic elements.
I have project packaged by Maven as a WAR. There are a number of other projects in the workspace on which the primary package depends. This arrangement has been working fine: I can deploy the WAR and the JARs it depends on under a Tomcat instance in Eclipse and the application runs and I can debug it.
Now I have created a new project that for the moment contains a single public class with a public constructor. The maven build works fine and the Eclipse compile workspace works fine. However, when I deploy to Tomcat and exercise an execution path that instantiates the class in the new project, I get a ClassNotFoundException.
I have checked the following items:
The Web Deployment Assembly for the primary package's project specifies WEB-INF/lib/ as the Deploy Path for the new project;
The JAR for the new project does in fact end up in the WEB-INF/lib/ folder under the actual deployment folder;
When I do a clean and publish on the server, the contents of the actual deployment folder do in fact get nuked and get repopulated with all the right JARs;
The new project's JAR as I find it the WEB-INF/lib in the deployment folder does in fact contain the class I am trying to instantiate;
The Tomcat log (which includes the startup cycle) contains no errors other than than the ClassNotFoundException;
I have re-done the Maven build and applied Maven build to the Eclipse projects numerous times;
I have cleaned and rebuilt in Eclipse numerous times;
I have cleaned and republished to the web server in Eclipse countless times;
I have created several new server instances.
Based on existing discussions of the ClassNotFoundException-in-Tomcat problem, these are the only things I have found to check. What else should I be looking into?
Thanks for your help.
Even for me the same problem has occurred .... I have clean the Tomcat and the Tomcat work directory and run the project again it worked fine...
This may happen because of the cache, sometimes which is not cleaned properly while building the application.
sometimes deleting the project from the eclise and importing it again doing it from scratch will also clear the problem
I'm not sure what exactly was wrong. However, I ended up resolving this issue by removing the project from the workspace, re-creating it from scratch, and importing my class into the re-created project.
Related
I've recently started learning Spring REST. As part of my learning process, I developed a simple Hello World application using Maven. The directory structure of maven offered by Eclipse doesn't contain the "
java" folder in src/main. So, I added it explicitly. It turns out the application gives me a 404 error as you can see in the below image. I'm sure this has something to do with the class path. As I'm new to maven I don't understand the concept of the classpath.
But in the second image, I created the project using "co.ntier" (maven archetype for Spring MVC). The directory structure of this archetype has got the java folder which is why when I run the application I'm able to get the output.
How to add or configure maven so that every time I create a new maven project, the directory structure will have the java folder? Please help me.
I recommend to always create a Maven project from an archetype.
You can e.g. use the quickstart archetype for a simple project.
The presence of a "java" folder has nothing to do with whether an application can successfully serve something at a particular url. They are not directly related. This also has nothing to do with the classpath.
However, the red mark on the project indicates an error, and as the DEFAULT location for compilable source in a Maven project is "src/main/java", it seems clear that the lack of the "java" folder results in the project not being deployed, which IS why you get a 404.
In short, if you have red marks in the project, it's not going to deploy.
The main question:
Has anyone else run into issues deploying to tomcat when dependencies are also open in eclipse as sister projects?
The Story:
Eclipse with the Maven plugin is smart enough to adjust the deployment assembly part of the configuration automatically, meaning that if you have a dependency in your web project and it is also open in eclipse, then you will get (among others) two entries in the deployment assembly listing:
One referencing the sister project and which outputs to WEB-INF/lib/sister-project-1.0.0-SNAPSHOT.jar
And a second one referencing the usual Maven Dependencies entry that outputs to WEB-INF/lib/
This however does not seem to work :/
ie. the jar from the sister project is not constructed/deployed out to the tomcat server, which of course results in the good old ClassNotFoundException.
Now, in the past, I swear this worked, but for some reason it doesn't in the ?current? version of eclipse (I'm running Version: 2018-09 (4.9.0)).
Current workaround:
Instead you run a quick maven-install on the sister project, and then close the project. This makes eclipse realize it needs to pull in this dependency as a regular maven dependency (from your local .m2), and since you just installed it there it has the most up to date version of your code.
The deployment assembly automatically updates, and just has:
The entry referencing the usual Maven Dependencies entry that outputs to WEB-INF/lib/
(The project reference is removed, as expected).
In this case, it goes ahead and finds the jar as part of the other maven dependencies and happily deploys it out to the server.
One theory I have is that it is wrong to want the output of the sister project (when it is open) to be a .jar, and instead should/could be routing it out to WEB-INF/classes/ along with the current projects class files.
Another theory, similar vein, would be that something is odd in the sister project where eclipse is not able to get a .jar file from it to output.
Hopefully someone else has come across this same situation before. :)
For me this works as expected in eclipse 2018-12 and also worked in 2018-09: The dependency when opened in workspace is built to a .jar and deployed into WEB-INF/lib.
There is a setting for this you should check for each participating project:
Project properties (Alt+Return) -> Maven -> [x] Resolve dependencies from Workspace projects,
When things are odd it also frequently helps to do a Maven project update:
Open the project context menu -> Maven -> Update Project -> All.
I had the same issue. The opened child project jar was in the WEB-INF/lib folder but somehow not seen by Tomcat.
I have resolved the issue by enabling "Serve modules without publishing" in the Tomcat configuration "Overview" page.
I have a web application (Eclipse's Dynamic Web App) which uses Maven (m2e-wtp) for the build and dependencies management. This web app's POM references a few other projects in my workspace, which happen to be eclipse plugins built with maven as well (built using Tycho), and also other third party libraries which come from Maven's repository.
Everything works fine when I run maven from the CLI. All dependencies are included in the WEB-INF/lib directory just as expected.
The problem is when I attempt to run the project using Eclipse. I run the app in a configured Tomcat server inside Eclipse, but the referenced projects in my workspace are not added to the deployed war.
I tried adding them to the Deployment Assembly (under project preferences), and that works perfectly, but those settings get wiped out by m2e every time the maven configurations are updated. I read in a few places that we should not manually add entries there since all dependencies should be managed by m2e...
The question is: How to make Eclipse add the workspace project dependencies to the WEB-INF/lib of my web app when I run it from Eclipse?
I'm using Eclipse J2EE 4.3.1 (Kepler SR1).
I also tried right-clicking the project and selecting Export -> WAR file, but the exported WAR file doesn't include the referenced workspace projects either. I'm assuming the issue is affecting both cases.
This is extremely annoying ans is slowing me down quite a bit.. at this time I have to re-add the projects to the Deployment Assembly page several times a day to keep it going...
UPDATE: The workspace projects I added as dependencies in the POM appear in the list of Referenced Projects, under the project's properties. But when I expand the Maven Dependencies in the Project Explorer, the workspace project dependencies are missing from the list! Only the ones in the Maven repository show up. They local ones seem to be silently ignored...
I had similar problem because I created the project outside eclipse, and them imported it. What worked for me was to add the right project facet: Project context menu -> properties -> Project Facets -> Dynamic Web Module (choose right version). I was using Eclipse ADT (version 4.2.0), but, to avoid having multiple installations, I use the same eclipse for Android and other kind of apps.
I'm developing a JavaEE system with several applications on a Weblogic AS (10.3.5) using Eclipse indigo with OEPE plugin. I turned my computer off, turned it back on, started the eclipse, and all of a sudden I get class-path errors all over the place (didn't change a thing).
Now let me get this straight:
1. Say I have an application with one EAR project that contains an EJB project and an EJBClient project (both in the deployment assembly).
2. I have written a new regular Java project, and I want to use it in both the EJB and EJBClient projects (it needs to be visible to them).
3. As far as I know, I can simply add this Java project to the EAR project's deployment assembly, and it will be visible to the EJB and EJBClient projects.
4. This has been working for me so far, but now I get class-path errors and I have to add this Java project to the build path of each project.
How should I set the class-path when using JavaEE technology in Eclipse?
After some tweaking I managed to solve the errors:
First I removed the library named 'EAR libraries' from the build path of each of my regular Java projects (I have no clue why Eclipse added them, they shouldn't be there).
Then, for each EAR project, I deleted and re-added every project or jar that was not part of the EAR (regular Java projects, other EJBClient projects, etc).
This solved the issue of not finding classes which aren't included in the EAR, but then I had a 'circular dependency' error.
I narrowed that error down to the projects that caused it - It was a regular Java project that was using an EJBClient project of some application in its build path, and the EJBClient project was also using the Java project in its build path.
Sounds trivial, then why havn't I seen it in the first place? Well, I looked into the EAR project of the application, and it didn't have the java project in the deployment assembly, and the EJBClient didn't have Java project as a 'required project'. So where was it?
The java project was in the 'EAR libraries' library of the EJBClient project, which, according to Eclipse, is automatically generated according to the 'MANIFEST.MF' file (which was empty, btw).
So I simply deleted and re-added the 'EAR libraries' library from the build path of the EJBClient project, and it solved the problem, and everything now works.
In conclusion, it seems like the OEPE plugin for Eclipse have some bugs that needs to be fixed.
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)