Running Maven project on glassfish server - eclipse

I want to run web based Maven project on glassfish server. I am totally new on maven. However, i have successfully build the maven project and glassfish server is up and running also. Moreover, there is WAR file also in target folder but i am confused what is the next step to run that project on glassfish ?
Any help will be highly appreciated.

You have different options to solve this task:
If you are new to Eclipse I suggest to change to NetBeans. It comes with integrated support for application server deployments. You just add your maven (or nearly any other type of project like WAR, EJB and EAR) project and your desired application server instance (Glassfish) and you are ready: Right-click your project and choose Deploy and it'll get deployed to your server. NetBeans also supports hot-deployment.
You can deploy your WAR file manually in GLASSFISH_ROOT/glassfish/domains/domain1/autodeploy and it'll get deployed if your server is running. But this is not very efficient during development.
If you want to stay with Eclipse you can use the maven-glassfish-plugin or this maven plugin to do the deployment for you. I'm not sure which one is better but this topic is also discussed in this question and this question.

Related

WebSphere Liberty Eclipse won't publish application to apps directory

I have a 4-project, Maven-based EAR application (JavaEE-7.0) with a parent, WAR, resources, and EAR project. I am using Eclipse Oxygen with the latest release of WAS Liberty 17.0.0.2 and the latest release of the WAS Liberty plugin for Eclipse Oxygen.
I have no error markers anywhere in any of my files and Maven can produce an EAR.
When I try to publish to Liberty, nothing happens. I've done all number of possible cleans: workspace cleans, Liberty server clean, Maven clean, etc. but even though the server says [Synchronized], nothing ever shows up in the apps directory of my server.
The server is locally hosted on Windows 10 and I'm using JRE 8u141.
When WLP starts up, it says CWWKZ0014W: The application foo could not be started as it could not be found at location blah.ear.
I've tried nuking my WLP installation and reinstalling from scratch; still no dice.
(Cue rant about tools keeping me from getting work done...)
How can I resolve this?
Are you using the Add/Remove dialog from the Servers view to publish the EAR to the server? This works for me using my sample maven EAR project.
A few things to check:
EAR project's Deployment Assembly page references the other projects
The WebSphere Application Server Liberty Targeted Runtime is checked on the Targeted Runtimes properties page for each of the projects
Project > Build Automatically is turned on (or you've done a Build All) in your workspace
Your server's server.xml should contain an 'enterpriseApplication' element after the publish
If the publish still doesn't work, can you provide more details about your EAR's pom as well as how you created the project. (using an archetype? based off of a sample? converted an existing EAR project to a maven project?)

Teaching Eclipse To Deploy an Ant Generated WAR File With JBoss Tools

I've been asked to migrate an older Ant-based web application. I'm building and trying to deploy using Eclipse Luna with JBoss Tools 3.0.1.Final. JBoss instance is EAP 6.3.0 (AS 7.1).
The build tool, like I said, is Ant. And when I run ant package, a valid WAR file is created at /target/foo.war
For some reason I'm having a heck of a time trying to explain to Eclipse and JBoss server that the foo.war file is what I want to deploy.
To this end I've:
Right-clicked on the project root and opened the Properties dialog.
Declared custom Ant builder for the project by going to Builders and adding an Ant builder and disabling the default Java builder.
Now Project -> Clean removes the target/ folder; Project -> Build results in a /target/foo.war file.
So far so good. At this point, I think all I need to do is declare that foo.war file as the Web Deployment Assembly? If I go to Web Deployment Assembly and click Add, then add the target/foo.war file, it tries to add it as a project library (i.e. WEB-INF/lib/foo.war). So clearly that's wrong.
I've also gone to the Server view, and tried numerous settings in the Deployment tab. The closest I've come to what I'm looking for is the Default Settings, but I haven't had any luck there, either.
(When I start JBoss via the JBoss Tools in Eclipse, then pull up the management console on port 9990, I can upload and deploy the WAR that way with no issues.)
I'm sure there's something completely obvious I'm missing. Could anyone help an IntelliJ user out? I have seen https://stackoverflow.com/a/4261178/3223711, but it seems to be missing the "last mile" in that the problem is not generating the WAR but in getting JBoss to actually pick it up and use it.
Thanks!
Since you are not actually not configuring the project to be a war project by Eclipse knowledge you need to tell JBoss Tools that you wish to deploy the specific war file.
To do this right click on the target/foo.war and select 'Mark as Deployable' - this tell JBoss Tools this foo.war can be deployed meaning you can now drag it to a server or add it via Add/Remove on the server.

Netbeans Maven project to IDEA 12

Short version: I would like to deploy Maven generated WAR to Local Tomcat server and not to build the war with internal IDEA process since the produced WAR file is not the same as the Maven generated one.
Long version: I have been using the Netbeans IDE for my Maven Java project. One of the modules is packaged as a WAR and should be deployed to tomcat server.
In Netbeans when I selected "Run" on the Web Module it asks for application server configuration then it runs the maven 'package' goal and deploys the application(generated WAR) to the Tomcat Server probably via Tomcat manager. So far so good.
We are now in the process of switching to Scala language. Scala classes extend old Java classes and the project is now "Mixed". I have configured Maven to compile the project as a mix of scala and java code. Maven produces a WAR which can then be deployed to Tomcat server without trouble - everything works as it should.
Now I would like to switch to Intellij-idea 12 IDE. But I have a problem: IDEA is refusing to deploy Maven created artifacts and insists of building one by it's own. The war is not the same and can't be used. Is there a way to tell IDEA to use Maven generated WARs and not try to make it's own ?
Just for the record I have already read these articles:
http://riddhimandas.com/blog/111
http://www.jetbrains.com/idea/webhelp/configuring-web-application-deployment.html Manually build WAR by IDEA - Want the maven generated one
IntelliJ IDEA: Maven, project compilation and deployment There is a hint here that IDEA can deploy Maven artifact from the 'target' directory but there is no information on how to do that.
With the help of CrazyCoder I figured it out.
You can make Intellij-Idea to upload your war by selecting External Source
But that's not all, even if you have a context.xml file difining your Context Root inside your WAR file: http://docs.oracle.com/javaee/1.4/tutorial/doc/WebApp3.html
You must specify one for every artifact you deploying (Unless someone will correct me)
The before launch section can be used to tell Idea what to Maven Goal to Run if any

deploying a war file in WTP(Eclipse) tomcat server

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.

Integrate War-Plugin for m2eclipse into Eclipse Project

I set up a small web project with JSF and Maven. Now I want to deploy on a Tomcat server. Is there a possibility to automate that like a button in Eclipse that automatically deploys the project to Tomcat?
I read about a the Maven War Plugin but I couldn't find a tutorial how to integrate that into my process (eclipse/m2eclipse).
Can you link me to help or try to explain it. Thanks.
I set up a small web project with JSF and maven. Now I want to deploy on a Tomcat Server.
During development I recommend to use Eclipse Web Tools Platform (WTP). M2Eclipse provides support for it (assuming you have Maven Integration for WTP installed) and your project should be recognized as a Dynamic Web Project runnable on a Server.
So, declare Tomcat as a Server (show the Servers view and right-click in it to add a Server via New > Server). And deploy your project to it (right-click on your project then Run > Run on Server).
There are other options like using the Tomcat Maven Plugin or the generic Cargo Maven Plugin but I wouldn't use them for development and, since you are a Maven beginner, I don't recommend them at all. Use your IDE.
I read about a the Maven War Plugin but I couldn't find a tutorial how to integrate that into my process.
Actually, the Maven War Plugin is only responsible of the packaging of your webapp project (it is bound automatically on the package phase when using a <packaging>war<packaging> for your project). It isn't used for deployment. But as I said, use your IDE to deploy your application during development.
The war plugin is for generating war files, not for deploying them. What you are asking for may be provided by the Cargo Plugin. Another interesting candidate for you could be the jetty-maven-plugin.