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

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

Related

How to deploy web application to Tomcat in Eclipse when placeholders need to be replaced with a value?

It is a maven project in Eclipse. We use ant clean package (ant call maven target) to build the war. During the build, ant use ExpandProperties to replace the placeholders in properties files.
For example, one placeholder in properties file like:
stub=${stubvalue}
During build, ant will replace the placeholder ${stubvalue} with a value from ant properties. So, finally all the placeholders will become actual value in the war file. Then the war file can be deploy and run successfully in tomcat.
Now in Eclipse, we create a tomcat server. Add and publish the web app to Tomcat server. However, obviously all the placeholders won't be replaced and deploy is failed when try start the tomcat in eclipse.
In this situation, what should be the proper solution?

eclipse dynamic web project with groovy nature copies .groovy files

I have an eclipse dynamic web project, and it has some groovy files (not a grails project though, just using groovy for some small backend stuff). I have added src/main/groovy as a source folder. However, when I select "Run on Server", it copies the actual .groovy file as if it were a resource. Is there a way to fix this behavior?
I was running into the exact same issue here. I have a web project here using the following:
Eclipse Kepler
Gradle
Groovy
Spring MVC
I have a Tomcat set inside Eclipse, from the command line or from the Gradle view I can compile, assemble and generate war files, however when I try to "Run on server" the files being deployed to Tomcat are the .groovy files, not the actual .class files, even though they are successfully generated inside the build/classes/main folder
So, TO FIX this I deleted and then re-created the Tomcat server within eclipse, after doing that it was able to find and deploy the right set of files compiled by Gradle
Hope this helps

How to make war file of gwt project in eclipse?

I am making web application using GWT toolkit in eclipse and my application is running successfully as we run from eclipse to right click on project and select Run as web project.
But when i make war file from eclipse-ide to Right-click on the project, pick Export, then WAR file so it does'nt work.It give me error "enter module name" it does'nt detect automatically module name. it happens only when i make a web application with gwt plugin otherwise in simple web dynamic application war file create easily with eclipse ide.i want to know how to make a war file in eclipse? And how to deploy my gwt application with tomcat server?
Thanks
Rahul
Take a look to this other question: create a .war file from gwt-project
In fact the real answer will depend if you want to use ANT or Maven.
WAR files are just compressed version of your built web app projects. One simple way to make them is to use jar.exe in JDK package. That's enough to run this command after building your project in eclipse to compress those files as a WAR file:
jar -cvf name_of_jar_file.war -C /path-to-app-built-dir /path-to-put-jar-file
The best approach is to use the command
Export > Export ... > Web > War file
You will have this command on the context menu (right mouse button on the project folder) if you installed the Java tools for Web Applications. Otherwise that should you first step.
It may be the case that your GWT project doesn't show on the selector of the Web Project field, the first on on the dialogue box when you execute the command above. If this is the case you must make sure you have the Dynamic Web Module facet on you project. Select the project root project navigator and then execute
Properties > Project Facets
and check Dynamic Web Module on the right panel if it not already checked.
You should make sure that the WAR directory used by GWT is the same used by the dynamic web module. If you are not sure what is your WAR directory (probably it's the one named "war") you can go to
Properties > Google > Web Application
and read the content of the field WAR directory on the right panel.
Then make sure that the WAR directory is specified in the "Web Deployment Assembly". You need to go to
Properties > Web Deployment Assembly
and check if your WAR directory is listed there. If you war directory is "war" then you should have /war on one of the rows with the deploy
path /. Otherwise
press Add...
select Folder
press Next
select your WAR folder (e.g. war)
press Finish
If you fail to make your WAR directory part of your Web Deployment Assembly them the Export > Web > WAR command will create a WAR file, but it will lack the web.xml and all the static files on the WebContent folder, such as the HTML, images, etc.
Open your project.
Navigate to war folder.
Go to File>Export>Archive File
Export your war FOLDER as zip file.
Change your file extension form .zip to .war
Keep calm and enjoy your war file.

Deploy a War file with Eclipse and Tomcat 6 without a build file

I know there are a bunch of posts on this topic, but I can't seem to figure it out. Here is my setup:
- Eclipse Indigo
- Tomcat 6
- Struts WAR file that I imported into Eclipse from http://www.manning.com/dbrown/SampleApplication.zip
I added the server to Eclipse, and added the project to the server. It runs fine, but I'd like to make some changes to the XML and java files (not the jsp files). I was under the impression that Eclipse takes care of the deployment after I save and restart the server, but I guess this isn't the case. I looked into creating an ant file to do a custom build, but I'm not really sure how to make it since I don't even know how to do a deployment "manually". How would I go about doing a manual deployment? Thanks.
A war file is usually created by exporting it from an IDE like eclipse, netbeans, etc.
While generating a war file there is 2 options,
You can include your java files with it
You can avoid java files from it.
In both the cases class files will be there which are created from java files. Class files will be able to take care of the actions of java class.
If the war file which you down loaded is not having those java files, you will not be able to use it with eclipse, where as it will work fine if you are putting it into tomcat directory for running.
For running a war file manually just put it into tomcat webapps folder and run tomcat.
Then you can access the pages using the url.
http://localhost:8080/yourprojectname/
If you want to check whether the war file contains any java files, after starting the tomcat server it will extract the war file into the same directry, where you can search for java files.
If you want to run the project from eclipse,
import it into eclipse, open index.jsp page
right click-> run as-> run on server
if you have not yet configured the server yet,select the server in the list, specify its installation path, then add projects into server in next step, finish it. then it will load your project.
Please provide little more details so that we can help you better.
manual: copy the war in the tomcat folder then start tomcat.
if you want to use eclipse you need to click redeploy war first by right clickling the deployed war in the servers tab under tomcat.

Deploying a WAR in Tomcat / Eclipse

I use Tomcat 6.0 and Eclipse 3.0 under Linux and I try to deploy a WAR in Tomcat. The problem is that the server is managed by Eclipse and I have some Eclipse project deployed. I tried to modify the server.xml file then launch Tomcat via Eclipse but it doesn't work:
Could not load the Tomcat server configuration at /Servers/Tomcat v6.0 Server at localhost-config. The configuration may be corrupt or incomplete.
I tried to extract the war in the webapps directory but the webapp is still inaccessible.
What is the best practice to deploy a War ?
Tomcat behaves differently in development and production mode. When you develop your webapp in Eclipse there is no reason to deploy a WAR file of your application as a WAR during development.
Just go to the "servers" view and add a new server (you should already have done this otherwise you could not create your Dynamic Web project). In the server view you should see the server you created (Tomcat at localhost or something similar) just right click it and go to the Add and Remove section. Here you can add and remove the Dynamic Web projects you created in Eclipse. Once you added your project, all you have to do is click the green start button in the servers view and your app should be available in at localhost:8080/mycontext.
When you're done building your app just right click the project and go the the Export section in the menu. You should be able to export a WAR file. Once you have your WAR file you can upload and deploy that on a Tomcat instance that is NOT tied to Eclipse running in dev mode.
Yes, in a way, you can deploy a war in the dev mode.
I have the same problem.
I have an Eclipse webapp project, which Eclipse deploys to an instance of Tomcat run by Eclipse, so I can hot-edit the project.
This Web project needs to use resources published by another webapp that has to be run within the same instance of Tomcat. The other webapp is a completed project by someone else, so it is already in a war form.
I needed to File->Import the war as an Eclipse project and let Eclipse deploy it to the same instance of Eclipse, in order to run it in the same instance of Tomcat in which my webapp also runs.
The problem is that some wars work this way but some others do not, while all of them work perfectly fine in a stand-alone Tomcat (started by startup.sh). I can't figure out why.
This is old but is one of the first answers in google search.
You can import the war file:
A Web Archive (WAR) file is a portable, packaged Web application
that you can import into your workspace.
Before importing a WAR file,
you should first determine if the WAR file contains needed Java™ source
files. When importing a WAR file into an existing Web project, the imported
Web deployment descriptor files are either not changed or overwritten by the
ones included in the imported WAR file, based on your response to the prompt
that is provided. In either case, this action does not represent a
merging of the two sets of deployment descriptors.
To import the
Web project resources in a WAR file into your workspace, complete the following
steps:
Select File > Import
.
In the Import dialog, select WAR file and
then click Next.
Locate the WAR file that you want to import using the Browse button.
The wizard assumes you want to create a new Web project with the
same name as the WAR file. If you accept this choice, the project will be
created with the same servlet version as specified by the WAR file and in
the same location. If you want to override these settings, you can click New and
specify your new settings in the Dynamic Web Project wizard.
Click Finish to populate the Web
project.
Source: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Ftwimpwar.html
If all you have is a binary WAR (no source code), it cannot be installed within Eclipse. This can happen in certain scenarios outside of normal development workflows. Here's the work-around solution:
Launch another instance of Tomcat (outside Eclipse).
Modify the tomcat-users.xml file to enable admin
Go to http://localhost:8080/manager/html
Scroll down to WAR file to deploy
Click Choose File (next to Select WAR file to upload) and click Deploy.