JBoss 6.1.1.EAP Module Deployment: Class not found - eclipse

The structure is as follows:
Actually deployed module is EAR.
EAR contains WAR module, and WAR module contains another JAR module.
In this last JAR, there are some generated classes and their parent folder is also used as source folder. Its path is "target/generated-sources/java".
The problem that is killing me, is that the deployed application throws ClassNotFoundException on server start, and the classes in question are the generated ones.
Now the trick:
if I explicitly change the Deployment Assembly in WAR project in Eclipse not to contain JAR project as "project", but as an archive from the JAR's project "target" folder, JBoss sees the generated classes and starts.
This solution however works only until next eclipse maven project update, so manual edit of deployment assembly is not really a solution.
Any ideas how to deploy or reorganise packages correctly?

OK, seems I have found the solution.
I looked through the build-path of the mentioned JAR file and saw that the entry Output folder pointed to target/test-classes.
After changing this entry to target/classes the application deploys and starts without any missing generated classes.

This is what worked for me:
Expand the 'target' folder of your maven project inside Eclipse (Project Explorer View);
Refresh it (F5);
Right click on your project on 'Servers' tab, then select "Full Publish";
Start your JBoss.
I had to enforce the JBoss Tool "Full Publish" to get an updated version of my target folder by Refreshing it manually on eclipse.
I don't know why but sometimes the Publishing from maven projects (even Full Publishes) do not copy classes from the target Project as it is in the file system. Maybe it's using some outdated memory info or some cache...
Anyway, this is what works for me.

After an update to Eclipse 4.15 and JBoss tools I got this problem too.
My solution: project -> properties -> Java Build Path --> Source
There my Output folder from my source was linked to project/target/classes, I changed this to project/target/project-projectversion/WEB-INF/classes
When I looked into the standalone JBoss folder I saw the folder structure of my source, but the classes where missing, when I changed the output folder the classes pop up and everything worked like before.
I am pretty sure the update made the problems.

Related

Why jars added to Deployment Assembly do not show up in Project Explorer (Eclipse Photon) under WebContent/WEB-INF/lib folder?

Working on a Dynamic Web Project I added a guava jar file to Deployment Assembly (Eclipse Photon) - thru Add -> Java Path Build Entry (same happens with Add -> Archives From File System)
I see that this jar gets deployed to the server and is actually inside /WEB-INF/lib of the generated and deployed WAR.
But my Project Explorer window looks like this and its WebContent/WEB-INF/lib folder is empty (I did project refresh)!
Is it normal behaviour?
In my opinion it breaks Least Astonishment Principle a lot!
It shouldn't appear there unless you actually copy the jar into the workspace (or link it, possibly).

Can't get eclipse kepler to deploy dependency projects of dynamic web project

I've recently upgraded from Eclipse Juno to Kepler, and have imported some old projects into a new workspace, but unfortunately I cannot get publishing of one of my web projects to work. It has dependencies on a couple of other projects in the same workspace, and these projects are listed in the 'deployment assembly' tab with entries like
Source Deploy Path
/eventserver WEB-INF/lib
that I have added using the 'Add/Project' option (I'm pretty sure I've previously used 'Add/Entries from Classpath' but that option does not list the projects, so I don't know what's going on). But neither the projects' code nor their dependencies are being deployed to WEB-INF/lib when I publish the main project. Also, I have the following warning showing up:
Description Resource Path Location Type
Projects must be referenced by an EAR or a WAR to use classpath publish/export dependencies whose runtime path (../) maps into the parent component. eventserver P/eventserver Classpath Dependency Validator Message
which I only used to get if I didn't have a main project that referred to the utility project.
Any ideas what's going on?
Create an EAR project using this link:
http://www.eclipse.org/webtools/jst/components/j2ee/scenarios/application_creation_tutorial.html
After creation, try to Add the Project in server entry.

eclipse - cannot get project export/dependencies working

Ok. I am using eclipse kepler.
Ihave an eclipse project called 'afd-core'. It has some classes, and a directory etc/hibernate containing hibernate config - lookup.hbm.xml.
I have another project afd-public. It is a webapp, and needs the stuff in afd-core on it's classpath.
And I think I have tried everything.
afd-public->project referencers: added add-core as a referenced project
afd-public->java build path->projects: added afd-core
afd-public->java build path->order and export: marked afd-core as exported
afd-core->java build path->added etc/hibernate as a classpath entry
afd-core->order and export->marked etc/hibernate as exported
Didn't work. When I run add-public as a web app, complains that it cant find the hibernate config.
So I made etc/hibernate a source rather than a class direcrory. Still didn't work.
Explicitly added add-core/etc/hibernate as a class directory in the add-public project. Still didnt work. Marked those class drectories as 'exported'. Still didn't work.
Manually copied the hibernate config into afd-public/webapp/WEB-INF/classes . Ok, it finds the hibernate config, but it does not find the core class files.
In other words, the afd-public webapp is not including dependencies from afd-core AT ALL, not in any way, shape, or form into the webapp that it deploys locally to tomcat. Whether or not I mark them as exported from afd-core. Whether or not I include the project or the directories explicitly. Whether or not I do or dont export them from the afd-public webapp.
Nothing. nada. Won't go.
Help?
Found it. Goddamnit - I needed to fiddle with Deployment Assembly in afd-public. It seems that there are a couple of ways to do it.
I can include afd-public/build/classes and afd-public/etc/hibernate and have them deployed to WEBINF/classes, or I can deploy the add-core jarfile to lib.
To get the afd-core jarfile correct, I create afd-core as a j2ee "utility project" and check that the Deployment Assembly there is correct. Which it is.

ClassNotFoundException when using User Libraries in Eclipse build path

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

Spring can't find a lib and webapp doesn't start up in tomcat 6

I've this problem using STS: I'm building a simple Spring app, just to try out features like MVC and persistence. Now I've created something very simple, out of a bunch of tutorials for Spring 3, that I'm using. The application fails with this, during server startup:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
but I've org.springframework.orm in web-inf/classes folder (I even tried putting it in web-inf/lib). As I copied these libs there, the came out in Web App Libraries folder. Building this project in STS works fine as this dependency is set up in build path throught project properties, but how do I transfer the libs to the web app? (I'm using Tomcat 6 as it is the server I'm going to use sometime in the future for production). Is this a config problem of my XML? Or am I just missing the right way to put this lib? (I encountered the same problem before, but adding the needed lib in classes worked it out). More than this I that if I browse inside my workspace to the folder where the working folder of tomcat should be, I can't find any work directory and any commo
Go to the Servers view and double click on Tomcat Server which will open up a Tomcat Overview page. This will show you the server path and deploy path which Eclipse is using to publish your webapps to.
For example, mine are:
Server path: .metadata\.plugins\org.eclipse.wst.server.core\tmp0
Deploy path: wtpwebapps
Now in a Command Prompt (or Explorer) browse to %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps and you should see your webapp. Go into the WEB-INF\lib directory and check if your jar is there.
A few things to try:
If the jar is not in WEB-INF\lib, you might need to republish it. Right-click on the Tomcat in the Servers view and click Publish. Does it appear? If not, Right-click on the Tomcat again and this time select Clean... which will clean out everything and republish. If this doesn't work, the brute force approach would be to delete the files manually and then tell Eclipse to republish them.
Clean your work directory, by right-clicking the webapp under Tomcat in the Servers view and selecting Clean module work directory. Or do it manually by deleting from %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost
You should also try closing-reopening/cleaning/rebuilding/refreshing your webapp project just in case Eclipse hasn't picked up the changes.
You need to put the various Spring JARs into your WEB-INF/lib directory (WEB-INF/classes is no use for JAR files).
You don't just need org.springframework.orm, you need most of them (see here for dependency diagram).
At least the libary jar files must be located at WEB-INF/lib within your war file. And you only need to deploy the war file to your productiv web server.
If you use STS but your Project is not a Maven project: then you need to put the files in <projectRoot>/WebContent/WEB-INF/libs .(to build the war with Eclipse/STS you need to execute Export/Web/WAR file.)
If you use Maven, then you need the specify your dependencies in the pom.xml, and use maven to package the war (run as/Maven package).