How do I build .war file in Eclipse for Glassfish server - java

I have web application written in java using Eclipse. It has just one servlet that does some file manipulations. How do I build war file so I can easily deploy it to my remote server.

Right-click on the project, select 'Export...', then choose web -> WAR.

You should be able to use Maven to package a WAR to deploy to your remote server. It looks a little daunting, but once you create your own WAR file you should be ok, check out:
http://maven.apache.org/plugins/maven-war-plugin/usage.html
In fact you should be able to manage deployment using the Maven Glassfish plugin here:
https://maven-glassfish-plugin.dev.java.net/
That will allow you to start,stop,deploy,undeploy etc... your web app. Example here:
https://maven-glassfish-plugin.dev.java.net/examples/complete.html

Just for the record,
The default build artifact for a
NetBeans Web project is a war
The default build artifact for a simple
Java project is a jar

Related

Eclipse JavaEE (Maven)project WAS 7 migration to IntelliJ

I'm trying to migrate a maven project from Eclipse to IntelliJ and would like to start/run/deploy to WebSphere portal.
My problem is that Eclipse IDE allows multiple open projects and one of the projects is an EAR that deploys a war file to WebSphere portal.
Eclipse Project structure:
Websphere Artifact deployed:
So how can I achieve the same thing in IntelliJ IDE using the already installed WebSphere?
I already configured successfully Websphere Portal and I can start the server but I donĀ“t know what type of artifact I'm supposed to configure here because there's no EAR artifact because that was a project back in eclipse:
If I go to artifacts setting for WebSphere I can add the war file, but it is not deployed.
I have googled a lot about this in IntelliJ documentation, IBM documentation but there are no concrete solutions, at least that I have the knowledge to implement. I'm a bit new to IntelliJ. Can someone share a light on this please, thx.
If it is a Maven-based project - just open and import it from the main pom.xml in IntelliJ IDEA - IDE will automatically configure project structure.
If Maven project has corresponding configuration for ear artifact - IDE will automatically create the artifact of the same ear type which then you will deploy to an application server.
If you do not configure ear in Maven, you can create one manually, see examples in documentation.
The name of your artifact is important, even if deployed as an exploded-archive. The file (archive) or directory (exploded) must end with .ear, .war or .jar. The default name set by Intellij may not work.
myProject_ear/ is wrong
myProject.ear/ is correct
The deployment system of your application server is likely configured to only deploy files or directories ending with the correct file-type. This is especially true if the server is using the file scanner to detect modules to deploy or un-deploy.

Deploying Eclipse Java Dynamic web project on Apache Tomcat permanently

I have a Java web project in Eclipse which I run through Eclipse on Apache Tomcat.
Is there a way for me to permanently deploy the project on Tomcat such that it runs without having to open Eclipse and rather just starting Tomcat?
If yes, then what steps do I need to follow?
*UPDATE*
If I take the .war file and deploy it on another system will it work? Note that I am using a MySql database in this project. So will transferring the .war file also transfer the database?
You package the project into a war file (since it is a web project) and put that one into the Tomcat's webapps folder. The deployment should then happen automatically, when Tomcat is started.
Generate a WAR file within Eclipse. (Properties->Export->WAR File)
Place this file in the {installation}/webapps folder of Tomcat.
It should deploy now.

Running Maven Struts2 app on tomcat

I created a Struts2 App using Eclipse M2 Maven plugin but there is no option to run the project on my tomcat server. I tried including the server runtime libraries in the projects build path but that doesn't work. How can I solve this problem?
In order to run project on server in eclipse, project must be in faceted form with Dynamic Web Module enabled. To convert project to faceted form: right click on project -> Properties -> Project Facets -> Convert to faceted form... -> check Java and Dynamic Web Module.
When you build the project, it should create an output, a war file or extracted war file. You need to deploy this on the server then only you can see the application. In eclipse I believe you can configure an server. Once you have configured a server in eclipse you can tell it to look for your project build output and deploy it.
Right click on the project and then Run As > Run on Server.
If you do not see that option that means your project is not configured as Web Application.

How to deploy a Java EE project to my webserver?

I'm working on my first Java EE project with NetBeans IDE. My application server is the integrated GlassFish.
At this moment my project run locally on my Mac with MySQL database. How can I deploy it on my web server?
You need to just create the war file and copy it to your web server. When you start your web-server it will automatically deploy the war file.
You need to use the remote application server functionalities of deploy.
If it's also Glassfish you can use the Administration Console to do it - e.g. example.com:4848 (defaut port for Glassfish admin portal).
Also you may use Cargo Maven Plugin in order to automate the deploy.
You have different possibilities:
Netbeans can deploy your application on the integrated Glassfish server. This should happen automatically if you Run you project and the Glassfish server is selected for this project. You can change the selected server for every project under Project Properties -> Run
You can deploy .war files via the Glassfish admin console if the Glassfish server is already started. Navigate to http://localhost:4848, go to Applications and click on Deploy
You can manually deploy you applications. You have to copy either the .war file or a folder containing the contents of the .war file to the folder /GLASSFISH_HOME/glassfish/domains/domain1/autodeploy

Can you publish a .war directly from eclipse to a web server

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

Categories

Resources