In eclipse, is there a way to specify a location other than the WEB-INF, for web.xml - eclipse

I want to place development web.xml in another folder in eclipse.

This can be done using the Deployment Assembly properties. Right click on the web project, choose Properties, and then navigate to the Deployment Assembly panel. Remove the /WebContent entry (pointing to /) and then add another entry, of type Folder. It should be rooted where you want to keep the web.xml, and mapped to /.
This technique can be extended to make Eclipse work with arbitrary build tool source layouts.

You might want to use Apache Ant
for that purpose. You may define a "conf" directory and place all you config files there, or a resource directory for the same reason.
If haven't use ant for that purpose, I strongly recommend you to do so.
Here is a sample ant build.xml for a web app Sample Build.XML
I'll use Maven myself, but since you're just beginning, Ant would be just fine.

I am using the eclipse builder and not ant.
Actually what i did was that i defined web.xml in another folder. So now I have two web.xml, one for welogic with a lot weblogic specific stuff like filters. And i have another for development which i placed in another folder, in the web project and added this folder to the deployment descriptor for tomcat in eclipse. So now when i deploy the application, the web.xml for tomcat which is in my specified folder owerwrites the web.xml present in web-INF folder(in the deployment directory).
Looks to me a nice workaround.

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).

When adding resources to a Tomcat server in Eclipse, what can be a resource?

When I bring up the "Add and Remove" resource dialog to add things like .war files (I think war is an example), I would like to know what sort of things constitute "resources" and how Eclipse identifies them as such. I am working on a new project that has a fairly complex Maven build and it is not clear to me what exactly I am adding to Tomcat. Could a directory be a resource? A pom file?
I should mention that I see a SNAPSHOT file (actually, the thing named this seems to be a Windows folder which does not hold jars) as a resource that can be added but the build does not seem to be producing a war or jar file which is named in this way. What does get added if I choose to add this resource seems to be composed of a bunch of jars or wars.
Perhaps you didn't create your project as "Dynamic Web Project", so Eclipse doesn't recognize it like a web project. Create new "Dynamic Web Project" or go to Properties -> Projects Facets and check Dynamic Web Module
It looks like entities other than jars can be added to a server.

JBoss 6.1.1.EAP Module Deployment: Class not found

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.

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).

I need Eclipse to deploy the WAR file my ANT script builds, not what it builds internally

I'm using Eclipse Helios. I have a dynamic web project going and I've set up Eclipse to use an Ant Builder to generate a WAR file. This all works fine; if I change a .java file, Eclipse automatically runs my build.xml via Ant and updates my WAR. If I deploy the WAR to an external instance of Tomcat, it works perfectly.
However, when I tell Eclipse to run my project under Tomcat, it is not using the WAR file generated by the Ant build, or using my Ant script to generate a temporary WAR.
I know this because my build.xml script includes some additional XML configuration files in WEB-INF/classes in the WAR that are not ending up in the WEB-INF/classes dir that Eclipse pushes out.
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
An alternate approach would be to tell Tomcat when it is building a WAR to do so by adding a list of files, but I can't seem to find a way to do that either.
I'm also curious how Eclipse knows what to publish since it is obviously ignoring my build.xml and my previously-generated WAR file.
Eclipse deploys a web application by looking at the Web Deployment Assembly options for your project. You can see this by right-clicking the project, choosing Properties, and then click on Deployment Assembly. Eclipse usually uses an expanded directory deployment here rather than creating and deploying a WAR (this is based on the server plugin being used, but I think most of them use an expanded directory structure for speed). If you export as a WAR it will create a WAR with the same content.
There are two main choices to do what you'd like:
Modify the Web Deployment Assembly options to match exactly what you would like in the deployed app
Don't use Eclipse's deployment; add an "External Ant Builder" to the "Builders" options for your project (right-click project, choose Properties->Builders). You can then select which targets in the ant file you want to use when eclipse builds the project. One of these options can be a deployment step
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
I'm an IntelliJ user, so take this with a grain of salt. But...
Right-click on the Project Explorer target/foo.war, select Mark Deployable.
Then right-click on the foo.war file again and Run As... -> Run On Server...
Choose the JBoss instance.
If you go to the Servers view, you'll now see your WAR file under the JBoss instance as /proj_root/target/foo.war
Oh Eclipse, sigh...