I have a mavenized web project which generates the war file. When I deploy this war file to the tomcat, it works fine. However, when I use eclipse to run the project on tomcat, it packages a different set of jars in the war and the deployment is unsuccessful. Would you have any pointers on how to get the same war file generated using eclipse as the one that i get using maven?
Thanks for the help
Right click on project
click on run as
click on run on server
set tomcat as your new runtime
then run
I hope it will help you.
Related
I am trying to build/deploy/run this maven/apache tomcat project LODE.
It's quite the first time I see this style of java web applications. I Followed the instructions provided on the website of this project. Started with maven clean install. Then an src folder was generated with a java folder (containing java classes) and a webapp folder (containing web resources) See the photo.
I am used to having a structure where a WebContent folder is there and a WAR file can generated.
.
How to deploy this project into apache tomcat and get it to run?
Here is what I tried:
I tried generating a war file by editing the build section in pom.xml file. However, it did not work.
I tried to add the project to Apache Tomcat 9 in my eclipse IDE. However, Tomcat does not believe that this is a web project, so I cannot add it (using right click on Tomcat -> Add/Remove).
I tried to take the generated webapp folder and deploy it to Tomcat (without eclipse IDE --> tomcat manager 'http://localhost:8081/manager/html' --> Deploy Directory) after creating WEB-INF/classes folder and moving the source qualified packages from the generated src folder to this folder. This did not work because the java classes were missing (cannot find the java class/package error).
LODE's README clearly says how to lunch the application. Well you don't see a war thus can't deploy on tomcat server.
I found two ways to make it work:
mvn clean jetty:run from the terminal. This will just work fine (runs on the jetty server).
For tomcat server, add <packaging>war</packaging> in the pom.xml to generate the war. Then either rename the generated war manually (for example, LODE-1.3-SNAPSHOT.war to lode.war) or use maven plugins to generate the war name. Now deploy this war to your tomcat server as usual.
I'm new to tomcat and maven configuration. I was given a single .war that has all the dependencies in it. I'm trying to figure out how to run the war file on a given port configured using a pom.xml file
I tried mvn tomcat:run-war where the .war file lives but it obviously needs a pom.xml How can I configure this to be able to run this?
If you have already compiled project with all the dependencies in it then it has nothing to do with maven (because it's a tool for building projects from source code).
In order to deploy a war file you should install standalone tomcat on your system and drop the war file into webapps directory in the tomcat installation home folder, then (re)start tomcat. Give it 20-30 seconds to launch and open http://localhost:8080/war-file-name-without-dot-war in your browser, if everything went right then you will see the deployed application.
I have set up a project inside Eclipse which I can debug on a Glassfish (3.1) server using the Eclipse Glassfish plugin. So when I click 'Debug on server', it uploads fine and I am able to step through the code correctly etc.
The problem is that I don't know if the program is being compiled/build (to a new .war) each time I press debug. I have got an Ant script in the project (as I previously built the project via terminal) but I'm not sure if it is actually being used in Eclipse.
Is there any way to check if my ant script is being run?
Also, how does Glassfish know what resources to upload? Does it just look for any .war files in the project?
Not sure about this particular jar plugin but as far as I know here is how Eclipse handles web applications:
Eclipse automatically compiles all of the sources in the class path
Then it creates a configuration file which tells Application Server to look for webapp on your project folder and does some mapping based
on your project setup. This will not create a WAR file. Eclipse will
just map WEB-INF/classes to {projectDir}/bin, your classpath jars to
WEB-INF/lib and so on.
When launching the Application Server, eclipse will feed it the config file made above.
Actually answering your question: Eclipse will not use the Ant script you created, nor will it create a WAR of any kind. It will just use project configuration to properly map project folders to web application structure.
Again, this is how eclipse handles things by default, the plugin you're using might do something different. This is based on my experience and is not based on some kind of documentation.
(Am a maven noob)
Have a maven built webapp which uses spring, etc.
When I run "mvn clean install", it generates a .war file in the target directory.
I copy the .WAR file to tomcat for deploying the app.
Debug the app
Edit the code
This process takes a lot of time. When I earlier used ant, I would point tomcat's server.xml to my webapps directory. Also, Eclipse would put all of its classfiles in my webapp\WEB-INF\classes folder. If I had to modify any JSPs, I would just edit and there was no need of additional copying. If I modified a .java file, Eclipse would build it and put the .class file in the WEB-INF\classes folder so that Tomcat would pick it up.
Now, each time I make changes to a .jsp, I need to manually copy the .jsp to tomcat's webapps directory. Isn't there a way that a maven built app can optimize this process ?
So, where do you point your tomcat at that makes development productive?
project (where pom.xml resides)
src
main
java
resources
webapp
WEB-INF
target
webapp
webapp.war
Basically, I would like to know how to configure eclipse(3.7.1) and tomcat/maven so that the edit/deploy/debug cycle is really fast.
UPDATE1
1) I was able to get m2e(http://download.eclipse.org/technology/m2e/releases/) installed in indigo(v. 3.7.1 of eclipse). it had 2 components
a) maven integration for eclipse
b) slf4j logging
It installed successfully asking me to restart eclipse. I restarted.
2) Next, I installed m2e-wtp (at http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/)
It had 3 components
a) maven integration for eclipse
b) maven integration for eclipse Extras
c) maven integration for WTP.
When I selected all 3, I got some error. So, I unselected the 1st two and only selected the 3rd one and then it installed successfully asking me to restart eclipse. I restarted.
#Raghuram
I ran the 4 steps that you suggested below. Only the 4th step resulted in an error and my webapp could not get deployed. It resulted in an error "File not found --- .svn/.wcprops/.
http://i.imgur.com/Pg1aq.png
What should I make of it ?
Thanks again,
I'd recommend you to use cargo to deploy automatically to a local container (that can be downloaded and started)
Maven+Cargo
Then having that started with jpa activated (so that you can remotly debug your code) you just have to attach a listener and debug from eclipse, intellij, whatever.
For JSP, talking Intellij, you must tell your IDE where to package files (right-click 'package file") which is done in the project setup (output classes dir in WEB-INF/classes)
Check Tomcat 7 - Maven Plugin? for an example cargo configuration for Tomcat 7. After the confiuration is valid you can deploy to your Container using mvn cargo:deploy and mvn cargo:redeploy
If you use Eclipse Indigo with m2e and m2e-wtp, you can pretty much develop and debug your web application without any manual step.
Add tomcat as a server in Eclipse
Import your maven project as a maven project in Eclipse.
Build the project (using Eclipse or using maven)
Choose "Run as server...".
Eclipse will pretty much take care of hot deploying jsps as well as classes on changes.
Can you publish a .war directly from eclipse to a web server.
I know it's not a programming question, but I still think it's a relevant question.
Thanks
yes you can.
right click on the project, select export -> select web - > then war and give destination which is your deploy folder.
Yes, but it depends a lot on your project configuration. Generally you need to define the server in eclipse, and choose "Run on Server".
See this as an example of deploying on JBoss server from eclipse.
In case you are using Ant then using "deploy" target will work.
This should be pretty easy:
Import the war file into eclipse. File > Import... > Web > WAR File.
(likely only works on eclipse for java ee development)
Pick the war file, create a new project (any new name works), click finish
Add the new project to your server
Blam!
If your project is setup as a web project in Eclipse, you can choose to run it on a server (You'll have to configure the server first). This will publish the war file directly on the server from Eclipse.
This is easiest if the web server has an auto-deploy facility, with a magic directory. Then just File-> Export the WAR file into the auto-deploy folder.
If not, or if you want to be able to debug the WAR file inside Eclipse you need to have an appropriate server connector in the WTP module (which is included by default in the Java EE edition of Eclipse).
If you want to programmatically push the WAR file to a given server directly from within Eclipse, then you can e.g. use the Tomcat Ant tasks - http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html#Executing%20Manager%20Commands%20With%20Ant - or use the Cargo library to do this with many different types of servers - http://cargo.codehaus.org/
I created my own ant file, and set eclipse to use that ant file when building.
Part of that ant build file is a target that publishes to Tomcat, so I can just right click
and chose install from within eclipse.
Eclipse pic http://img408.imageshack.us/img408/6701/eclipseant.png
The basis of such an ant file is here: http://tomcat.apache.org/tomcat-6.0-doc/appdev/build.xml.txt
Yes, you do that
Start the build the application
Create the war file
A WAR (or "web archive") file is simply a packaged webapp directory. It is created using the standard Java jar tool. For example:
cd /home/alex/webapps/mywebapp
jar cf ../mywebapp.war *
- copy that war file to the following deploy directory in your server
say in Jboss its like this
"C:\Jboss405\server\default\deploy"
I hope this might be clear, else let me know any issues if you face any issues