I have created a maven project in Intellij Idea. I also added jetty's maven dependency to pom file.
What should I do then to create servlet project?
Should I create webapp\WEB-INF\web.xml folder in main\java manually? or there is some maven plugins which I must add to Pom.xml file and after clicking install in Lifecycle, related folders and files will be created automatically?
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.c.helloWorldMavenServlet</groupId>
<artifactId>helloWorldMavenServlet</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I recommend to use maven archetype to create project:
org.apache.maven.archetypes:maven-archetype-webapp
Then you should create directory java in src/main,then right click-> Mark Directory As -> Sources Root.
By default, you have web.xml in version 2.3 so that's mean you cannot user CDI for example.
If you want to change it go to File->Project Structure->Facets(or Modules) and then delete Web Descriptor from Deployment Descriptors and then add new web.xml(+) and choose version 3.1.
I hope it should work. At this moment I don't know any other way to achieve that
Related
I have two projects - A and B, where A is dependent on B. I package B as jar and deploy it on a maven server (artifactory), and then include that jar as a normal dependency on project A in pom file. jar file of B shows up in the Maven Dependencies of project A, but dependencies of project B are not shown in dependency hierarchy. It is causing class not found exception for dependencies of B.
However, my project A and B and in same eclipse workspace. When I open project B, project A starts referencing the project B from the workspace instead of remote repository and everything works well.
This question - Maven. Transitive dependencies was closest to my problem, but dependencies of my project B are NOT optional.
Whats going wrong here?
POM for project B
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>utils</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>utils</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Following doesn't get added to project A -->
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
POM for project A
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>core-app</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>core-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.myapp</groupId>
<artifactId>utils</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
</dependencies>
</project>
I am using maven quickstart archetype. Project structure of my projects is (which I package as jar):
project-name
src/main/java
src/test/java
pom.xml
To successfully resolve transitive dependencies, project B's jar and pom.xml must be accessible in the Maven repository. When deploying artifacts to a remote repository, be sure both the jar and pom.xml are deployed and available for download.
With the requisite files deployed to the remote repository, use the command line to build project A. Specify a build Maven target to trigger the downloading of all dependencies into the local Maven repository. Something like mvn compile or mvn package will trigger the downloads and successfully build project A.
Once, project B's jar and pom.xml are in the local Maven repository, update the Maven projects in Eclipse and they will rebuild and resolve the dependencies correctly.
I have three modules of a project, getting developed as two seperate jars and one WAR. WAR is referring to two other jar. Please see the details below-
1.processDAO-this is a java Project producing a jar(processDAO.jar)
2.ProcessModel-this is a java project producing a jar(processModel.jar). And in pom.xml it is referring (processDAO.jar)
3.ProcessWebApp-this is Main web app project as War producing (processWebApp.WAR). Now this is using (processModel.jar)
Now currently after each development when I need to build the WAR file I first build -(processDAO.jar)
then 2nd- processModel.jar
and in last I build ProcessWebApp.WAR
So each time I have to follow this sequential build process. Now, I want whenever I go to build my ProcessWebApp.WAR other dependency gets build automatically in same sequential manner(1->2->3).
Any advice on this will be very helpful.
Environment I am using Eclipse which have mavenplugin. I just right click on every project and do RunAs 'Maven install'.
1.processDAO.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>processDAO</groupId>
<artifactId>processDAO</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
2.ProcessModel.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProcessModel</groupId>
<artifactId>ProcessModel</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>processDAO</groupId>
<artifactId>processDAO</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
3.ProcessWebApp.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProcessWebApp</groupId>
<artifactId>ProcessWebApp</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>ProcessModel</groupId>
<artifactId>ProcessModel</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Listen there several issues with the way you have created your pom or what you want to achieve.
A minor comment on the existing samples is to fix the <groupid> element usually it is something of com.xxx.my.company and is not identical with the artifact id.
Now from what I understand it seems that you are still changing the code on the dependent modules, so that means you are releasing SNAPSHOT versions (otherwise you wont need to check the compatibility of your libs every time right?). See this question on using xxx-SNAPSHOT here
Also check the use of the -U flag mvn clean install -U . See mvn -help.
-U,--update-snapshots Forces a check for missing
releases and updated snapshots on
remote repositories
This is usually achieved by use of a parent project POM, the only purpose of which is to build the modules that it depends on. When creating the POM, specify the packaging type as 'POM' and then specify your WAR and JARs as module elements. There's a pretty good example and description of this on Sonatype's site here.
I am new to Selenium and Maven tools. Trying to set up the Selenium 2.0 Java project using Maven, via this guide.
After creating and saving pom.xml in my project directory, I run mvn clean install and get the following error:
(...)
The goal you specified requires a project to execute but there is no POM
in this directory (C:\Users\User\Documents\TestAutomation). Please verify you invoked Maven from the
correct directory. -> [Help 1]
My pom.xml looks like this, as in the example from the link:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MySel20Proj</groupId>
<artifactId>MySel20Proj</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
</dependencies>
</project>
I have Maven 3.3.1 and Java 1.8.0 installed on Windows 7.
Any idea, what am I doing wrong? I have little experience with testing tools in general.
OK, the problem was with the file extension. It was actually saved as pom.xml.txt, not pom.xml as I expected. (found that via dir command)
I have created project using this command:
mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
After downloading libraries my project looks like this:
http://i43.tinypic.com/2iut1me.jpg
How can I "tell" maven to download jars in just one folder?
Maven will not download jars in a single folder, instead, it create a dir structure in a $HOME/.m2/repository for managing your dependencies, including versions.
If you want the jars to show in the Eclipse project, create a pom.xml file in your project with the correct dependencies, for example
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.myGroup</groupId>
<artifactId>myProject</artifactId>
<name>myProjectName</name>
<version>myProjectVersion</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>dependency1</groupId>
<artifactId>dependency1</artifactId>
<version>dependency1</version>
</dependency>
<dependency>
<groupId>dependency2</groupId>
<artifactId>dependency2</artifactId>
<version>dependency2</version>
</dependency>
<!-- .... and so on -->
</dependencies>
Also, configure your project in eclipse to be a Maven project and then you will see "Maven Dependencies"in your project.
I've installed the following maven module to my local maven repository
EWS Maven Module but the IDE (Eclipse in this case) doesn't seem to know about the following class `GetUserAvailabilityRequest.
Interestingly, I can run a mvn compile on my project that uses the dependency above successfully.
I can even see the class file in the jar file under my Maven Dependencies in Eclipse.
Does anyone know why this might be occurring ?
Edit #tolitius:
ews-java is a dependency for my project, not the project I'm trying to import
Here is the pom file in question:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.conf</groupId>
<artifactId>conferenceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>microsoft.exchange</groupId>
<artifactId>exchange-ws-api</artifactId>
<version>1.1.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Turns out that the class in question is not public. It had nothing to do with Maven or Eclipse or anything.I wasn't looking at the class since I didn't have the source attachment.