Why Tomcat library folder WEB-INF/lib is empty? - java

I deploy my Maven webapp using Spring MVC in Eclipse Tomcat. Everything works OK for quite a week. Suddenly, today I modify a properties file, rebuild and redeploy the webapp. There's a class not found error:
SEVERE: Error configuring application listener of class org.jasig.cas.client.session.SingleSignOutHttpSessionListener
java.lang.ClassNotFoundException: org.jasig.cas.client.session.SingleSignOutHttpSessionListener
Look at publish folder (tmp0) of Tomcat server plugin located in workspace folder, there are no jars in WEB-INF/lib any more. I don't know why? I have rebuilt/deployed it many times today, and have found no problem.
Could someone give an advice? Thanks very much.
EDIT:
I can't find a right solution for this problem, though I temporarily bypass it by removing the web app from Tomcat Server, do a clean up, then add it back again.

Do you have m2eclipse WTP integration installed? There are few things you could try:
Maven->Update project configuration
Close and open project
Remove project from Tomcat instance in WTP, Clean up and add it back.
Depending on your version of Eclipse and m2eclipse/m2e and WTP the integration could be finicky sometimes.

Is this option enabled? ProjectName (right-click) > Maven > Enable Dependency Management
You should have in ProjectName > properties > Java Build Path > Libraries an item called Maven2 Dependencies
Is your M2_REPO variable set? Window > Preferences > Java > Build Path > Classpath Variables
If it's all ok, check the war that Maven is creating to see if the libs are there and in the correct folder (web-inf\libs). Check the maven output when generating the war.

Related

How to get eclipse to deploy dependent maven project to tomcat when also open?

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.

How to debug issues with deploying to tomcat from eclipse?

I've inherited a Spring web app. It's a gradle web app project that I've imported into Eclipse. We're using Eclipse 4.7.3, Tomcat 7.0.47 and JDK 1.8.0.151.
The problem is that when I deploy the project to Tomcat from Eclipse, some of the dependency jars are not copied to the project lib directory. When TC tries to start the web app, there are ClassNotFoundException errors.
I'm new to Java web apps, so what I need is some tips for verifying my project import/build/deploy.
Here's what I've done so far:
Install Tomcat 7.0.47 (don't start it after install) Install Eclipse
4.7.3 JavaEE flavor (which comes with Buildship Gradle integration 2.0 installed)
Import my project as a Gradle project (File -> Import -> Gradle ->
Existing Gradle Project). I point at the project root, choose the
web project for deployment, and use the default settings.
Add a server to the project (from Server view click Add -> choose
Tomcat 7.0 -> point to TC root)
Right click the web target and select Run As -> Run As Server and
choose the TC 7 server I added.
At this point the project builds and deploys. The console shows the TC log. TC starts but the shows an error when it attempts to start the web app (for example):
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
I could copy jars but it's my impression Gradle should be grabbing the dependency jars during deployment. I can verify that some are copied, but others are missing. How can I debug this issue?
Here's part of my build.gradle file
buildscript {
repositories {
maven {
url projectDownloadUrl
}
}
dependencies {
classpath lib_license_gradle_plugin
}
}
The web app is deployed to ...eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0. The lib directory here contains some of the deployed dependency jars. The gradle.properties file contains a list of dependencies, for example
lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1
This is apparently not the place to ask and answer Gradle/Tomcat questions. I figured out the issue shortly after posting, and not wanting to disappoint the 40 people who've come here for help since then, thought I should finally answer my own question.
First, I was on the right track on how to debug deployment of a gradle/maven app in Eclipse. After it deploys you can check which jars are in the deployment directory. Eclipse deploys locally to a place similar to c:\users\\eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core.
Second, the immediate problem I was having was due to using Tomcat instead of Tomcat EE. The answer to this was right in the question:
lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1
Tomee is Tomcat + Java Enterprise Edition, which includes some extra logging and other jars, the ones I was missing.

Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server

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.

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)

maven2 war overlay and eclipse WTP

I have a maven war module which run eclipse WTP tomcat server like normal. Now i want to reuse that module artifact by using maven war overlay: i just create a new war project and include that module in project dependencies. The problem is now i cannot use eclipse "Run on server" anymore because i don't have any resource or config file (like web.xml) in the new project, everything is in the war dependencies but eclipse cannot resolve it.
Is there anyway to use a maven war overlay project run with eclipse ?
Thank you.
If you're trying to have a war dependency on a war project, in other words doing a "war overlay", then it's not currently supported by m2eclipse
Jer developped a plugin to implement this feature, you can give it a try : http://code.google.com/p/m2eclipse-wtp-ext/
I've test this(to debug my first JASIG CAS server), and found it works in eclipse:
Using Jetty Maven Plugin to run/debug war overlayed web apps.
Hope helpful~
I am having the same issue here. I agree with you that it's not supported yet (and has not been for almost 2 years!). There seems to be an alternative using q4e version 0.11.0+: http://wiki.eclipse.org/IAM_WTP_support which you can download from https://code.google.com/p/q4e/ or using the update site http://q4e.googlecode.com/svn/trunk/updatesite-iam/ . I'll give it a try and see whether and how it works (with m2eclipse at the same time active).

Categories