EzDevInfo.com

maven-2 interview questions

Top maven-2 frequently asked interview questions

Run a single test method with maven

I know you can run all the tests in a certain class using:

mvn test -Dtest=classname

But I want to run an individual method and -Dtest=classname.methodname doesn't seem to work.


Source: (StackOverflow)

Find Oracle JDBC driver in Maven repository

I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14. In MVNrepository site the dependency to put in the POM is:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc14</artifactId>
    <version>10.2.0.3.0</version>
</dependency>

of course this does't work as it is not in the central repository used by maven. 2 questions:

  1. How do I find a repository (if any) that contains this artifact?

  2. How do I add it so that Maven will use it?


Source: (StackOverflow)

Advertisements

Convert Existing Eclipse Project to Maven Project

For a project at work, we're considering using the Maven plugin for Eclipse to automate our builds. Right now the procedure is far more complicated than it ought to be, and we're hoping that Maven will simplify things to a one-click build.

My question is, is there a wizard or automatic importer for converting an existing Eclipse Java project to a Maven project, using the Maven plugin? Or should I create a new Maven project and manually copy over all source files, libs, etc.


Source: (StackOverflow)

Is there a simple way to remove unused dependencies from a maven pom.xml?

I have a large Maven project with numerous modules and pom.xmls. and the project has changed that much that I'm sure the pom's must have some unnecessary dependencies in them. does anyone know if there is a command you can run to remove any pointless dependencies from a pom?


Source: (StackOverflow)

How do I tell Maven to use the latest version of a dependency?

In Maven, dependencies are usually set up like this:

<dependency>
  <groupId>wonderful-inc</groupId>
  <artifactId>dream-library</artifactId>
  <version>1.2.3</version>
</dependency>

Now, if you are working with libraries that have frequent releases, constantly updating the <version> tag can be somewhat annoying. Is there any way to tell Maven to always use the latest available version (from the repository)?


Source: (StackOverflow)

Sharing Test code in Maven

How can you depend on test code from another module in Maven?

Example, I have 2 modules:

  • Base
  • Main

I would like a test case in Main to extend a base test class in Base. Is this possible?

Update: Found an acceptable answer, which involves creating a test jar.


Source: (StackOverflow)

Build Maven Project Without Running Unit Tests

How do you build a Maven project without running unit tests?

Currently restructuring some code I have for a Servlet and would like to try it out in my web browser (which means running mvn install to get the .war to upload to Tomcat). I'm fully aware my UNIT test are failing and I'm fine with that because I will fix it once I have the code the way I want. Can anyone advise?


Source: (StackOverflow)

Differences between Ant and Maven [closed]

Could someone tell me the differences between Ant and Maven? I have never used either. I understand that they are used to automate the building of Java projects, but I do not know where to start from.


Source: (StackOverflow)

Can I add jars to maven 2 build classpath without installing them?

Maven2 is driving me crazy during the experimentation / quick and dirty mock-up phase of development.

I have a pom.xml file that defines the dependencies for the web-app framework I want to use, and I can quickly generate starter projects from that file. However, sometimes I want to link to a 3rd party library that doesn't already have a pom.xml file defined, so rather than create the pom.xml file for the 3rd party lib by hand and install it, and add the dependency to my pom.xml, I would just like to tell Maven: "In addition to my defined dependencies, include any jars that are in /lib too."

It seems like this ought to be simple, but if it is, I am missing something.

Any pointers on how to do this are greatly appreciated. Short of that, if there is a simple way to point maven to a /lib directory and easily create a pom.xml with all the enclosed jars mapped to a single dependency which I could then name / install and link to in one fell swoop would also suffice.


Source: (StackOverflow)

force Maven2 to copy dependencies into target/lib

How do I get my project's runtime dependencies copied into the target/lib folder?

As it is right now, after mvn clean install the target folder contains only my project's jar, but none of the runtime dependencies.


Source: (StackOverflow)

Maven command to determine which settings.xml file Maven is using

How do I use maven command line to determine which settings.xml file Maven is picking up?


Source: (StackOverflow)

How can I create an executable JAR with dependencies using Maven?

I want to package my project in a single executable JAR for distribution.

How can I make Maven package all dependency JARs into my JAR?


Source: (StackOverflow)

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file?

I have a project the builds into a single jar file. I want the classes from dependencies to be copied into the jar as well.

Update: I know that I cant just include a jar file in a jar file. I'm searching for a way to unpack the jars that are specified as dependencies, and package the class files into my jar.


Source: (StackOverflow)

Why do so few people use Maven? Are there alternative tools? [closed]

I am new to Java, and when I started my development, my friends recommended Maven for project management. I almost immediately realized that it is an indispensable tool, and at that time I was thinking that all programmers use it. But when I see statistics on the NetBeans site, I was in shock: 67% of developers are not using Maven. Why? Are there some alternative tools that make project management easy?

UPDATE

I agree with feicipet on 100%.

1) IDE independents it's really good. This was proved on my own experience. First, our team used the Eclipse, then we decided to switch to NetBeans, the people who help us with the project using IDEA. And it does not matter because the project can be run even with the console:)

2)Well structured and clean project. I think Maven structure convention is very helpful, because tests and main code are separate.

3)Project management. Maven it is not only build tool, it give you ability to configure you environment, run unit tests, and create reports.

For me, it turned surprised when the experienced programming talk about the difficulties of Maven, when I saw Ant in some project Maven showed me a miracle. And all comments about the complexity of the transition from Ant are strange. This is two different logic, what do you expect?

There are some problems with documentation, this is really bad. But I think this situation will change for the better


Source: (StackOverflow)

What causes a new Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?

I imported a Maven project and it used Java 1.5 even though I have 1.6 configured as my Eclipse default Preferences->Java->Installed JREs.

When I changed the Maven project to use the 1.6 JRE it still had the build errors left over from when the project was using Java 1.5 (I described these build errors earlier in: I have build errors with m2eclipse but not with maven2 on the command line - is my m2eclipse misconfigured?)

I'm going to delete the project and try again but I want to make sure this time that it uses Java 1.6 from the start to see if this eliminates the build problems.

How do I make sure the project uses Java 1.6 when I import it?


Source: (StackOverflow)