My gae + spring + maven project works perfectly. But I can't make it work using eclipse.
Seems like the spring-web dependency declared in my pom.xml is disappearing from WEB-INF/lib when I run my project using GAE from eclipse (using Google Plugin, Run As > Web Application). So without spring-web this is the exception:
Could not instantiate listener org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
(Full GAE stacktrace here)
From console, running mvn clean package gae:run, the app works like a charm and spring-web is placed under WEB-INF/lib directory as expected.
Just published my test project at BitBucket: https://bitbucket.org/jelies/gae-spring-maven
Any idea why spring-web is not being published to WEB-INF/lib when launching webapp from eclipse?
Using:
SpringSource ToolSuite 3.1.0 (based on eclipse 3.8)
Java 6
Spring 3.2.1
Maven 3.0.4
Google App Engine 1.7.5
maven-gae-plugin 0.9.6
Update: spring-web dependency is being published to WEB-INF/lib when using spring version 3.1.4.RELEASE. This is not happening with any 3.2.X version.
Added a Jira issue for this problem with my configuration (Eclipse 4.2, WAS 7.0, mvn 3): https://jira.springsource.org/browse/SPR-10494
If your .classpath file has the entry <classpathentry kind="output" path="target/classes"/>, try changing it to your WEB-INF/classes dir. Mine is set up with maven standards, so I changed this line to <classpathentry kind="output" path="src/main/webapp/WEB-INF/classes"/>. This just fixed my issues (Eclipse Juno, WAS 7, no m2e install).
Also, in case it applies to others, I should mention that with my server (Websphere) I am choosing the "Run server with resources within the workspace" publishing setting.
This issue shows how much I really don't understand Eclipse's publishing still, but before that change when I chose the "in workspace" setting it actually published my resources to \workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0 and the WEB-INF\lib did not contain spring-web. However, with the change above I'm no longer seeing my code published to that directory. I'm not exactly sure now how my server is getting the binaries it needs, but it appears to be working.
As a side note/added bonus (maybe completely unrelated), I no longer need to do a publish to see updates to my JSPs when I make changes to them.
This fixed it for me:
Find the location of the spring-web.jar this is being included in you web app. In my case its in user.m2\repository\org\springframework\spring-web\4.1.6.RELEASE\spring-web-4.1.6.RELEASE.jar
Open spring-web-4.1.6.RELEASE.jar en eg. 7zip
Delete this file from the jar: META-INF\web-fragment.xml (in 7zip right click the file -> delete)
Close 7zip and run "Publish" on the server in Eclipse
More info: https://jira.spring.io/browse/SPR-10494?focusedCommentId=94572&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-94572
Definitely, spring 3.2.x with eclipse and maven is not working; spring-web is not being published to WEB-INF/lib when launching the application from Google Eclipse Plugin.
Tried with Spring 3.2.1 and 3.2.2. It's only working for me using lower versions (now I'm using 3.1.4).
Related
I have maven based project with following structure:
main_project
module_webproject
module_java_proj_1
module_java_proj_2
module_java_proj_3
... ...
Everything compiles and packages fine with command line maven goals execution. I need to setup this project into eclipse environment for developers with tomcat deployment. Anyone know setup instructions?
Also, i am looking into tomcat hot deploy for debugging capabilities.
I have tried mvn eclipse:eclipse, this does only creation of .project and .classpath files. But projects directories are not treated as java or web projects.
Answer from following forum some what helps...
[Running Maven project on Tomcat from Eclipse
There can be a few reasons why you don't see the project in the Add/Remove projects dialog for Tomcat. Verify the following:
You have m2e installed (http://eclipse.org/m2e/download/)
You have m2e-wtp installed (http://www.eclipse.org/m2e-wtp/download/)
Your Maven project imported as a Dynamic Web Application. Look for a Deployment Descriptor entry when you expand the project, it should be somewhere in the first few entries. It is the second one down for me on Eclipse Juno. Not there? It's probably not a web app. Go back and verify 1 & 2, then remove and re-import your project.
Make sure that your web application is not too new for the version of Tomcat that you are using. Right-click the project and go to Properties > Project Facets. Look for Dynamic Web Module and check the version. If this version is too new for your Tomcat version, Eclipse won't let you add it. For instance, your Dynamic Web Module version is 3.0 and you're using Tomcat 6.
I have a basic question about running a Java EE application on Weblogic using maven in eclipse.
I use OEPE (Oracle Enterprise pack for Eclipse) which comes with some plugins such as m2e and wtp. As far as I know this plugins read the pom file and based on them build the jar, war and ear files.
What I do right now is like this:
I check the build automatically option and let these plugins create my EAR file, then right click on the instance of weblogic server in Eclipse and add it to server using add/remove option and finally start the application server. This way when I change code in my classes they will be picked by application server and hot swap works.
Another way to build the EAR file is using the m2e plugin: right click on the parent pom file and choose maven install then start the application server and use the wls:deploy in order to deploy the EAR file. (This time I don't add the ear file to the application server from within the Eclipse and eclipse also is not aware of that EAR file when I right click on the instance of my weblogic inside the IDE).
As far as I've seen I can only add those artifacts to server which are built using the wtp plugin and not the artifacts that are built using maven command of m2e plugin. The problem with wtp and all these plugins (except for m2e which actually just runs mvn -install) is that they don't work flawlessly. Sometimes they don't build the artifacts correctly sometimes the jar files are obsolete and they don't get updated. Moreover when you use the jar file of one project in another maven project they get stuck with the jar file prior to your changes, while using the m2e they are built flawlessly.
Now here is the real question:
Which way is the correct one to have hot deploy?
Am I missing something? Is building the ear file using m2e plugin and deploying using wls:deploy enough? If so how will hot swap happen by itself or should i use wls:redeploy each time? If m2e is enough then I assume that I should abandon wtp plugin (it does not know all the plugins of pom file and I should sometimes mark them as ignored in lifecycle management xml file of eclipse).
I'm sorry that the question is that long but I hope that I made the case clear and get some help!
Let me provide you with my checklist to make my web application hot-deployed on Weblogic. This checklist assumes a weblogic version which implements Servlet 2.5 and assumes your project is a maven one which is configured to run maven-compiler-plugin for JDK 1.6.
In other words your weblogic version is 10.x.x and your POM includes the following snippet:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
To build a war
Use OEPE plugin to create a new Weblogic Web module Weblogic.xml file:
Don’t enable spring extension
In FastSwap: Don’t enable class redefinition
Take note of the value
<wls:context-root>myappcontextroot</wls:context-root>
it will be used later in the hot-deployment
Execute Maven update project from Eclipse context menu of your project
Execute Maven clean install
For hot-deployment setup:
Add local weblogic as a runtime server in Windows->preferences->Server->Runtime. Remember to change its Java home to the Sun JDK instead of JRocket for development mode.
Add local server in Server->add server
Project context menu->properties->Project Facet-> add faceted nature
Make Sure Jave Facet is version 1.6
Check Dynamic web application version 2.5 and make the target runtime be the runtime server declared in the first step + In further configuration give “context root” the value "myappcontextroot" which was noted above and give “Content directory" the value "src\main\webapp”. Don't generate web.xml otherwise your web.xml is overwritten
Push OK to apply all the above facet changes to your project
Again open Project context menu->properties->Deployment Assembly->Add java build path->Maven dependencies
Finally, in the server window Add configured application to the running server
Please follow these steps literally, it is really worth it!
Disclaimer: this is not a duplicate of the "why isn't my JDBC resource declared in META-INF/context.xml taken into account" genre questions.
I have two Java EE web applications:
one is created inside Eclipde IDE using Eclipse's "Web Application Project" template
the other one is created using Maven, and then imported into Eclipse
Inside Eclipse I also have a Tomcat configured using the WTP Plugin, such that I can easily (or so I hoped) deploy my Eclipse Web Apps in there in a "one button push" way.
For each of the above described applications, I have a context.xml file placed in their META-INF directory, in which I declare some JDBC datasources as JNDI resources.
The Eclipse created application works fine when deployed in the WTP Tomcat inside Eclipse. I right-click the Tomcat server in Eclipse, add the project, start it and it all works fine, the JNDI datasources are found etc.
For the other project, the one created with Maven and imported inside Eclipse, if I add it to the WTP Tomcat, and manually specify where the war file was built by Maven (in the "target" dir) it seems to work, but the JNDI datasources are not found, more specifically, my Spring declared datasource:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/whatever" />
throws an exception saying no JNDI name is bound for "whatever".
If I deploy the very same war file in a "regular" Tomcat (just un unzipped Tomcat, no Eclipse involved) it works fine and the JNDI datasource declared in the war's META-INF/context.xml is found.
I've looked inside Eclipse's Tomcat working dir, and sure enough while for the Eclipse created project the context.xml file is copied inside "{catalina home}\wtpwebapps\eclipeProjectName\META-INF\context.xml", there's no such file (and folder structure) for the Maven project.
My question is then: does anyone know how you can have a Maven-created web app imported inside Eclipse and deployed in WTP Tomcat such that the META-INF/context.xml file is taken into account?
As you've mentioned that you are using the Eclipse Helios. There is a alternative one provided by JBoss as the Eclipse Update Site. The document told us as the following: -
The following folders should never be removed as they are part of composite
requirement sites used for current/previous JBoss Tools releases:
Helios SR2: 0.13.1
Indigo SR2: 0.15.3
Juno (SOA Tooling Integration Stack ONLY - may not be needed much longer?): 0.14.0
Juno SR1 (can be removed when we have a Juno SR2 target platform instead, if anything newer exists): 0.16.0
Please note, before the Eclipse Juno, I used Helios and Indigo with this plugin. It also gives me a good result.
I hope this may help.
I have a maven build Java project.
My war file name is: test-1.0-SNAPSHOT.war
I am using M2E plugin in Eclipse.
I have run target mvn package.
Added server as tomcat version 7 in eclipse indigo 3.7. Server started. But my war file didn't deployed in the server.
I have tried by right clicking tomcat server and Add remove..., it says "there is no resources that can be added or removed from the server".
How can i deploy my war file in the eclipse WTP tomcat server?. Do i need to run any maven target?
Make sure that you have "Maven Integration for WTP" installed in your Eclipse instance.
First check if it's available through
Window->Preferences->Maven->Discovery->Open Catalog
If for whatever reason this does not work, you can get WTP integration from this update site (that's the version I am currently using):
https://repository.sonatype.org/content/repositories/forge-sites/m2eclipse-wtp/0.13.0/S/0.13.0.20110623-0455
This integration does a lifecycle mapping of maven-war-plugin into m2e architecture.
Once you've installed the WTP integration, you must restart eclipse and once it's restarted, right click on your web app project and choose: Maven->Update Project Configuration...
Also, I would advise to run a clean build at this time.
Last, but not least, delete and recreate your Tomcat server configuration (I don't know why, but I had to do it quite a few times when I switched to m2e).
I think eclipse is not recognizing your project as a web app, To confirm this
Open to do open J2ee perspective on your eclipse, If you open the project folder of your app, You should see (Deployment Descriptor)
If you don't see it, your app is not web app as far as eclipse is concerned
I have see this in case if you imported/created a maven command line project
To fix this
Select Project ==> Properties ==> Project Facets ==> make sure Dynamic Web Module check box is checked
If you do that the local tomcat server will add your app when do add remove projects
I think eclipse is not recognizing your project as web app,convert your project into web app by command mvn eclipse:eclipse -Dwtpversion=2.0 and try to deploy in Eclipse configured tomcat,it will work.
If you have Eclipse 3.5 or above you should ensure that you have both the m2eclipse (m2e for 3.7) plugin installed and its WTP add-on. With these you shouldn't need to change your configuration by hand.
Did you try to build your project from the command line and deploy it in Tomcat by hand?
By the way, have you read this wiki post? It's a bit old, but it may still be relevant.
Adding 2 cents to Prasanna wonderful solution.
I realized that building maven war files "mvn package" was just creating .war file but eclipse was not picking up that war but was deploying its some internal version of it's app war.
I found that server > Browse Deployment Location.. in Eclipse server view .. it was taking to some abstract location like "C:\Programs\workspaceSTS.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps"
Where I could see my exploded app deployed but it was not having any /classes folder just limited files.
Using Prasanna's method I realized that eclipse now was deploying full exploded .war now.
So this was happening coz changing the facets to Dynamic Web Module has actually populated "R-click project > Properties > Deployment Assembly "
This Web Deployment Assembly window only tells eclipse what to deploy and what not. So even if your project is NOT setup as Dynamic Web Module , and still if you configure "Web Deployment Assembly" values properly , eclipse will deploy the app fine to Tomcat/ Server.
I started a new dynamic web project in eclipse helios. I integrated glassfish into eclipse and it works fine so far. Except one thing:
I place my libraries (jdbc, log4j etc.) in WEB-INF/lib. Eclipse deploys that files correctly to glassfish, but glassfish does not include that directory in its classpath, so my app won't run (because it can't find the jars).
When I edit the server's "launch configuration" in eclipse, I can manually add the libs under "Classpath", but that don't change a thing.
Only when I manully copy the jars to glassfish's lib/ext folder, the libs are included.
When I used tomcat as a server it works, the libs are in tomcat's classpath. But I want to use glassfish without copying the libs manually.
Any idea?
Not sure how do you add the libs in your project.
Try to show the project properties tab, select the Deployment Assembly node section, and click the add button. Select archives from file system or project (if your lib i also an Eclipse j2se project).
This should work.
Hoping you use the latest Eclipse 3.6 SR1 and the latest glassfish plugin from the update Center: http://download.java.net/glassfish/eclipse/helios
My servlet did not find the jdbc driver, so I thought it was a lib missing. Calling “ClassForName“ solved the problem. This seems strange to me, as this is not needed when used in the SE context.
So eclipse is correctly deploying the libs, just a little extra code is needed.