I am currently working on a web app in Eclipse that I plan to push to Heroku. I am using the maven Eclipse plugin (m2e) for downloading dependencies for my app. Maven works great except for one thing.
Maven is downloading all my dependencies into ~/.m2 which is fine except for one thing. When I push my app up to Heroku those dependencies won't go up with it, so I need the dependencies within the project file system. So my problem is finding the best way (or any way in fact) to get the dependencies into my project.
I'm still a noob so any help is appreciated!
If you have a maven plugin in your eclipse, you can configure this directory on:
Window - Preferences -> Maven -> User Settings
But this is not you problem, because this maven file system is just to archive your repositories and the maven don need download it everytime.
Maybe you need to configure a war plugin in yout pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Related
Sorry if this is too trivial, but I've recently jumped into Wep Applications from standard console java projects, and since in java projects I successfully used maven to download jars and include them into the classpath... in the web app I don't know how to accomplish the same stuff and downloading to the lib folder on WEB-INF instead of just adding the jars to my classpath.
I have searched stack overflow and the google for an answer, but since I haven't found any single answer, I'm afraid I should be completely wrong with my approach for this.
I have just created my webapp on eclipse, then converted it to maven project, and then added this dependencies in pom.xml, as I used to do in a normal java project:
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
Everything seems to be ok, and no error is shown, but the jars are not downloaded into the WEB-INF/lib folder.
Thanks in advance for any help you can provide.
If your project is correctly configured as "Maven project" there should be a folder called "Maven Dependencies" in your package view.
A good hint if your project is configured as Maven project is a little "M" on the top level folder.
Eclipse will download in a so called "Repository". This is mostly located in $HOME/.m2
Generally you don't have to care about jars directly. Maven will download them and create a classpath transparently for you.
The eclipse maven integration is called m2e.
The concept of Repositories is central to maven. They are the place where your dependencies and external dependencies are stored. Two repositories you can always assume to exist are the already mentioned local one and the other so called "Maven-Central" see here. Beside that you can setup , for example, company wide Repositories with tools like Nexus or Artifactory.
To upload a dependency in your local Repo use the mvn install command.
What maven within mvn install is executing the install lifecycle.
and then uploads the resulting artifact (generally a jar or war, but not necessarily) and some metadata (your pom mainly) to the repository.
You can then develop against these dependencies via the dependency mecahnism.
Dependencies in you installed in your local Repository are always of type "SNAPSHOT". There is more to know about the difference between SNAPSHOT and Release (only version number) and how to deploy/release them, but these questions are already awnsered several times.
Adding this plugin to pom.xml will help to get jars in lib folder.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>WebContent/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Without using maven, to run the app on tomcat from the Intellij IDE, all you have to do is create an artifact and a "tomcat" run configuration pointing to that artifact, this way you can see tomcat output, restart the server, and other stuff right in the IDE.
Now using maven, there's no need to create an artifact, because maven already does the compiling, packaging, etc.
I know i can deploy it using the command mvn tomcat7:redeploy but this way i can't see standart output/errors and debug.
So what is the standard way to run the app from IntelliJ without having to create an artifact?
In pom.xml add
<build>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<uriEncoding>UTF-8</uriEncoding>
<path>/your-path</path>
<update>true</update>
</configuration>
</plugin>
</build>
In IntelliJ, open Menu > View > Tool Windows > Maven Projects
Plugins > tomcat7 > tomcat7:run
If you have set
<packaging>war</packaging>
in your pom, IDEA should automatically identify the artifact (your WAR file) to deploy. No need to manually create an artifact.
When you setup this: n IntelliJ, open Menu > View > Tool Windows > Maven Projects, you will see this menu:
When you click on this picture you can enter the goal of Maven, for example tomcat7:run
Hi I have multimodule maven project something like this..
parent
Core
Web
and my Web project depend on Core project classes so i added Core project as a dependency in Web project pom.xml file.
But from inside eclipse when i am running Web project the lib directory does not contain Core-project.jar file in class-path so project not running. How can resolve this issue?..Plugin I used in my Web Projec *Pom.xml* file..
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
And i am using Tomcat6 Server.
this Dependency tag in my Web Project pom.xml File...
<dependency>
<groupId>org.csdc</groupId>
<artifactId>core-java</artifactId>
<version>5.0.0</version>
</dependency>
And When i run web project from inside Eclipse i am not getting core.jar in this path....
workspace_maven.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\web\WEB-INF\lib
Anyone got any such issue .If yes please let me know how can i resolve this issue?
Under Eclipse : you do not need to have your core.jar in your classpath. Check your librairies (web->properties->java build path->librairies), you should see your core folder and not your core.jar.
Make sure that "resolve workspace dependencies" is checked in your maven build target.
Install the m2e and m2e-wtp plugins for eclipse. m2e-wtp handles web projects and tomcat. You don't need the plugins sections of your pom that you've documented in the question.
For maven to work with projects in eclipse you need to ensure that the parent project is at the same level as the child projects and the pom of the parent project is like below
<modules>
<module>../project1</module>
<module>../project2</module>
</modules>
Unfortunately this is the only way to get maven to work correctly in eclipse and jenkins for multi-module builds.
Not exactly clear that this is what you are looking for, but the jars won't appear under your lib directory in eclipse because they are in your repository.
My version of eclipse has a 'maven' menu when I right click on the project. If yours does too then make sure that you have 'Enable Maven Nature' selected. This will make a small M appear next to the project name and a new folder in the project, which contains all of the dependencies listed in your pom.
1.Go to web project build path -> Libraries - Add variable -> Configure Variables -> New -> Enter Name as M2_REPO and Path as C:\Users\usernmee.m2\repository and click Ok.
All the dependencies will configured in the project build path. So no compilation error in web projecct.
2.Maven project need to take war and deploy it in any web container(tomcat,etc).
Check the war in your target directory after running mvn clean package. If it is missing there, check the scope of your dependency for "Core" in your pom.xml for "Web", make sure that it is not provided or test.
It sounds like from your pom fragment that you are using mvn eclipse:eclipse (which you shouldn't be anymore), instead use the m2eclipse plugin: http://www.sonatype.org/m2eclipse.
Install the correct set of plugins and configure them correctly.
If you need a more detailed answer, you should give us more information what you tried to achieve, which plugins you use, what kind of web server, how you deploy, whether you use Maben to deploy or the Eclipse WTP, etc.
[EDIT] You won't see anything in project/WEB-INF/lib when you start the project in Eclipse - there is no point putting anything in there because this folder isn't used.
Instead, you probably deploy the project to a web server. There are plugins for Eclipse which can do that (i.e. start a web server, deploy your project into it) but since you don't mention how exactly you "start" the project inside of Eclipse, which version of Eclipse you're using and which buttons you click, how you configured Eclipse, etc. it's really hard to help you.
Over the past few days I have been trying to create/run a project in Eclipse using the gwt-maven-plugin and keep running into roadblocks (see some of my previous questions). I like to use Maven to do my builds, but I'm at the point where I'm thinking of going the Ant build route because of the complications of using Maven.
Does anyone out there have it configured/working well? Is it just me or is this harder than it should be?
After much frustration trying to get things to play nicely together, this is the setup I have that "works" for me. "Works" meaning that I can create, run and debug a GWT project with tweaks, but it isn't the most elegant solution.
Create Project
Much of the steps are the same as Pascal's answer in this post: Maven GWT 2.0 and Eclipse. I'll list mine out to be clear.
In Eclipse (Helios) with m2eclipse and GWT Eclipse plugins installed:
Create a new Maven project using the gwt-maven-plugin archetype
Modify the pom.xml:
set <gwt.version property> to 2.0.4
(needs to be same as GWT Eclipse
Plugin version)
set <maven.compiler.source> and
<maven.compiler.target> properties to
1.6
remove <goal>generateAsync</goal>
from gwt-maven-plugin <plugin> config
add maven-war-plugin to pom.xml
maven-war-plugin example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<warSourceDirectory>war</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
Update project Properties:
Google -> Web Toolkit, check the "Use Google Web Toolkit" box, and ensure "Use default SDK (GWT-2.0.4) is selected.
Run Maven "gwt:eclipse" goal on project (sets up environment and launch config)
Copy *.launch file to workspace.metadata.plugins\org.eclipse.debug.core.launches
Restart Eclipse
Compile/Run Project
I created a Run Configuration that does mvn clean compile gwt:run. The gwt:run is necessary to copy the resources and lib jars into the war directory. However, it does not copy the web.xml from src/main/webapp/WEB-INF into war/WEB-INF/. So, I have to manually copy that file.
If I want to run my application, the above step is sufficient. However, if I want to debug the application, I launch it by choosing the Google "Web Application" configuration from Debug Configurations that was created when the .launch file was copied previously. This configuration allows for debugging (breakpoints etc.) without any other config or need for remote debugging.
It is harder then it should be, however it is possible. All hints posted here can do the trick. However you can still have classloading issues. I decided to switch to GWT 2.1 and use new abilities of JettyLauncher. You can create own jetty launcher like this:
public class MyJettyLauncher extends com.google.gwt.dev.shell.jetty.JettyLauncher {
#Override
protected WebAppContext createWebAppContext(TreeLogger logger, File appRootDir) {
return new WebAppContext(appRootDir.getAbsolutePath(), "/");
}
}
And then add -server MyJettyLauncher option to your gwt launcher configuration. With such configuration all the libraries are managed by m2eclipse (you can even remove GWT SDK from classpath) and there is no need to copy anything to WEB-INF/lib (you can remove gwt-servlet.jar which could be already there).
Ready launcher is here in tadedon library:
http://code.google.com/p/tadedon/source/browse/tadedon-gwt-dev/src/main/java/com/xemantic/tadedon/gwt/dev/JettyLauncher.java
Yes, in 2016 it does, quite nicely indeed. :)
I launch Tomcat from within Eclipse, I launch GWT codeserver (SuperDev mode) from Eclipse, I launch Chrome from Eclipse.
You will find quite recent and very valuable set-up tutorials on Brandon Donnelson's YouTube channel: https://www.youtube.com/user/branflake2267/videos
What is essential for me is Eclipse debugger for GWT SuperDevMode: https://sdbg.github.io/
I prefer to have my project "mavenized", and there is lot of Maven archetypes also provided by Brandon: https://github.com/branflake2267/Archetypes/tree/master/archetypes
The official starting point (not just) for downloading the GPE plugin (not to confuse with above mentioned debugger plugin) is on GwtProject.com: http://www.gwtproject.org/download.html
For me personally GPE itself has become rather optional "convenience" component. (Yes, refactoring and auto-completion are nice to have, but that's all it is needed for. :)
It is not a one-click solution, and I prefer it like that, as those tend to be black-boxes prone to breaking.
And BTW make sure to take a look at GWT Material: http://gwtmaterialdesign.github.io/gwt-material-demo/
(Currently playing with 2.8-beta1.)
For Eclipse I use: m2eclipse plugin (1.0). It works well with one or two minor things. Also download the m2eclipse-extras plugin to add SVN functionality AND Maven (or CVS if you prefer).
When you download then your project it reads the pom.xml and [re]creates the Eclipse configuration files like the mvn eclipse:eclipse command.
For GWT... I've used it too. It's a pretty twiked configuration but it works. I use GWT 2.0.3, the maven-gwt-plugin uses the dependencies to work (no ref to GWT SDK) and it can debug from Eclipse which is simply great.
You have to compile to a war directory (not the target/classes standard). But the details are in my work, so let me see it tomorrow and complete this answer :) Don't give up. It's a great thing to have GWT+Eclipse+Maven.
Edit: part of my configuration
<build>...
<outputDirectory>war/WEB-INF/classes</outputDirectory>
...
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<gwtVersion>${gwt.version}</gwtVersion> <!-- para forzar que use el de maven y no el SDK instalado -->
<disableCastChecking>true</disableCastChecking>
<disableClassMetadata>true</disableClassMetadata>
<runTarget>/subscriber/listSubscribers.htm</runTarget>
<webappDirectory>${basedir}/war</webappDirectory>
<soyc>true</soyc>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- dont know/remember if the jetty inside the gwt uses this... but it doesnt hurt-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<configuration>
<webAppConfig>
<contextPath>/magazine</contextPath>
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>
${basedir}/src/main/webapp,
${basedir}/war
</resourcesAsCSV>
</baseResource>
</webAppConfig>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8888</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargets>
<scanTarget>${basedir}/war</scanTarget>
</scanTargets>
</configuration>
</plugin>
AND
For debugging I create two tasks:
1) maven build inside eclipse that runs two goals: war:exploded gwt:debug
The first one copies all the resources into war directory for gwt debug to use them.
Next the gwt is ready.
Maybe you need to execute gwt:compile for the first time
2) a Java Remote Application debug configuration, with your project selected.
You run this configuration when the gwt:debug is "listening at port 8000"
AND: this is in a parent pom.xml (sorry I'll edit this post later :)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
<webappDirectory>${basedir}/war</webappDirectory>
<warName>${artifactId}</warName>
</configuration>
</plugin>
helios wrote good explanation. But it's not actual at the moment. So I advice you to try my modern example of EAR application running on GlassFish and with full debug support.
I'm having a hard time to make my Maven2 multi module project, with a deep project structure, appear as a single ear (with its dependencies - which includes 1 war, 2 ejbs and 1 jar) to be deployed in my JBOSS 5 server inside my Eclipse Ganymede (tab Servers).
I've been trying to use Maven Eclipse Plugin to turn my projects into a WTP project without success. Therefore they appear to be deployed in the server they appear as separated projets.
My project has 1 war, 2 ejbs and 1 jar that must be packaged inside an ear, each of the "subprojects" is a separate module.
Project's pom.xml (type pom):
...
<modules>
<module>ejb1</module>
<module>ejb2</module>
<module>war</module>
<module>jar</module>
<module>ear</module>
</modules>
...
The ear module is only responsable to pack the other modules together.
Is there a way to tell eclipse (ganymede) that all those projects (ejbs, war and jar) are inside the ear module so I can deploy the ear in the server?
What you want to do is have maven create the eclipse projects via mvn eclipse:eclipse This might be helpful.
try m2eclipse (google it) and install the WTP integration tool, create a project using the maven wizard, change the type to pom in the pom xml editor, create a sub modules from the pom and that adds it as child, if its a web project it get the WTP behavior i.e it can be deployed to a j2ee container ( jboss / tomcat ), add a dep to the web module for ejb module in the web pom etc, deploy the web app to the container
Installing the m2eclipse with the optional WTP configuration worked for me. I also added the following to my parent pom to ensure the right natures and builders in the eclipse files
This yields eclipse .project files that are ready for m2eclipse. then I can Update the project files using m2eclipse allowing hot deploy the webapp and its dependencies
<build>
...
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5.1</version>
<!--
Eclipse project natures: http: //vikashazrati.wordpress.com/2007/12/22/adding-project-nature-to-your-maven-pomxml/
Maven-eclipse-plugin: http: //maven.apache.org/plugins/maven-eclipse-plugin/
-->
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>org.eclipse.jem.workbench.JavaEMFNature</projectnature>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
<projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>org.eclipse.wst.jsdt.core.jsNature</projectnature>
<projectnature>org.maven.ide.eclipse.maven2Nature</projectnature>
</additionalProjectnatures>
<buildcommands>
<buildcommand>org.eclipse.wst.jsdt.core.javascriptValidator</buildcommand>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
<buildcommand>org.eclipse.wst.common.project.facet.core.builder</buildcommand>
<buildcommand>org.eclipse.wst.validation.validationbuilder</buildcommand>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
<buildcommand>org.maven.ide.eclipse.maven2Builder</buildcommand>
</buildcommands>
</configuration>
</plugin>
use -Dwtpversion=2.0 parameter of maven or on command line mvn -Dwtpversion=2.0 in super pom project. i use m2eclipse plugin but has got some issues for multi module project. I use m2eclipse plugin for dependency management. If i want to clean, install etc. all project with super pom, i do it on command line. Also project properties must check in eclipse. Project Facets, Java EE Module dependencies must check. You can also export to ear project, but be carefull to check maven modules is compiled after changing.