Maven interview question set 2/Maven Interview Questions and Answers for Freshers & Experienced

What is the reason for using an Optional Dependency?

1. Optional dependencies are used to decrease the transitive burden of some libraries.

2. These dependencies are used when it is not feasible to divide a project into sub-modules.

3. Some dependencies are only used for a specific feature in the project, and if that feature is not there, then that dependency will not be used.

How can a Maven Build Profile be activated?

A Maven build profile may be activated in the following ways:

1. Explicitly using command console input.
2. Through Maven settings.
3. Based on environment variables.
4. OS Settings.
5. Present/missing files.

What is MOJO?

MOJO can be defined as a Maven plain Old Java Object. Every MOJO is an executable goal in Maven, and a plugin refers to the distribution of such MOJOs. MOJO enables Maven to extend the functionality that is already not found in it.



What is the Maven settings.xml file?

The Maven settings.xml file contains elements used to define the values needed to configure Maven execution differently.

It contains the following configurations:

> Proxy configuration
> Local repository configuration
> Remote repository configuration
> Central repository configuration

What is the command to install the JAR file in the local repository?

The command to install the JAR file in the local repository is,

• MVN install

What are the ways to activate profiles?

A Maven build profile can be activated in the following ways,

• By environment variables (User/System variables).

• By OS Settings.

• By using command console input explicitly.

• Present/missing files.

• Through maven settings.

What is the exact function of “jar:jar”?

It is essentially used to create a JAR file primarily from the dictionary of the target classes. Contrary to what most tend to think, the command is not meant for the recompilation of resources.

How do you produce error messages in Maven?

There are various commands to produce debug messages. For instance, the most popular is to call Maven with an X parameter or an e parameter.

What is meant by a goal in Maven?

A) Executing a phase means executes all previous phases. Plugin is a collection of goals. Plugin is a class and goals are methods within the class. Maven is based around the central concept of a build lifecycle.

Where are Maven dependencies downloaded to?

The jars , dependency files and other files which are downloaded by Maven reside in the Maven local repository. By default the Maven local repository is the .m2 folder. You can copy the jar directly into where it is meant to go. Maven will find this file next time it is runs.

What is a maven assembly?

The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.

What is the use of Maven clean?

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

Where are Maven dependencies stored?

The maven local repository is a local folder that is used to store all your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, when you build a Maven project, all dependency files will be stored in your Maven local repository.

What are the Maven advantages over Ant?

Convention over Configuration – Maven uses a distinctive approach for the project layout and startup, that makes easy to just jump in a project. Usually it only takes the checkount and the maven command to get the artifacts of the project.

Project Modularization – Project conventions suggest (or better, force) the developer to modularize the project. Instead of a monolithic project you are often forced to divide your project in smaller sub components, which make it easier debug and manage the overall project structure

What is wrong with maven?

Maven is not easy. The build cycle (what gets done and when) is not so clear within the POM. Also, some issue arise with the quality of components and missing dependencies in public repositories.

The best approach (to me) is to have an internal repository for caching (and keeping) dependencies around, and to apply to release management of components. For projects bigger than the sample projects in a book, you will thank maven before or after.

What Is Target, Source & Test Folders In Maven?

Target: folder holds the compiled unit of code as part of the build process.
Source: folder usually holds java source codes.
Test: directory contains all the unit testing codes.

What Is Difference Between Compile & Install?

Compile: is used to compile the source code of the project Install: installs the package
into the local repository, for use as a dependency in other projects locally. Design patterns
can also be used with Groovy. Here are important points.

How do you convert input stream into string?

If you have java.io.InputStream object, how should you process that object and produce a String?

Suppose I have an InputStream that contains text data, and I want to convert this to a String. For example, so I can write the contents of the stream to a log file.

What is the easiest way to take the InputStream and convert it to a String?

public String convertStreamToString(InputStream is) {
// ???
}

A) A nice way to do this is using Apache commons IOUtils to copy the InputStream into a StringWriter… something like

StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
or even

// NB: does not close inputStream, you can use IOUtils.closeQuietly for that
String theString = IOUtils.toString(inputStream, encoding);
Alternatively, you could use ByteArrayOutputStream if you don’t want to mix your Streams and Writers

What is force maven update?

mvn clean install -U
-U means force update of snapshot dependencies. Release dependencies can’t not be updated this way.

How do you host a Maven repository on github?

I have a fork of a small open sourced library that I’m working on on github. I’d like to make it available to other developers via maven, but I don’t want to run my own Nexus server, and because it’s a fork I can’t easily deploy it to oss.sonatype.org.

What I’d like to do is to deploy it to github so that others can access it using maven. What’s the best way to do this?

A) The best solution I’ve been able to find consists of these steps:

Create a branch called mvn-repo to host your maven artifacts.
Use the github site-maven-plugin to push your artifacts to github.
Configure maven to use your remote mvn-repo as a maven repository.
There are several benefits to using this approach:

Maven artifacts are kept separate from your source in a separate branch called mvn-repo, much like github pages are kept in a separate branch called gh-pages (if you use github pages)
Unlike some other proposed solutions, it doesn’t conflict with your gh-pages if you’re using them.
Ties in naturally with the deploy target so there are no new maven commands to learn. Just use mvn deploy as you normally would
The typical way you deploy artifacts to a remote maven repo is to use mvn deploy, so let’s patch into that mechanism for this solution.

What is an uber jar? What does an uber-jar mean and what are its features/advantages?

an uber-jar is an “over-jar”, one level up from a simple “jar”, defined as one that contains both your package and all its dependencies in one single JAR file. The name can be thought to come from the same stable as ultrageek, superman, hyperspace, and metadata, which all have similar meanings of “beyond the normal”.

The advantage is that you can distribute your uber-jar and not care at all whether or not dependencies are installed at the destination, as your uber-jar actually has no dependencies.

All the dependencies of your own stuff within the uber-jar are also within that uber-jar. As are all dependencies of those dependencies.

What are the methods for constructing an uber jar?

ubar jar is also known as fat jar i.e. jar with dependencies.

There are three common methods for constructing an uber jar:

Unshaded: Unpack all JAR files, then repack them into a single JAR. Works with Java’s default class loader. Tools maven-assembly-plugin

Shaded: Same as unshaded, but rename (i.e., “shade”) all packages of all dependencies. Works with Java’s default class loader. Avoids some (not all) dependency version clashes. Tools maven-shade-plugin

JAR of JARs: The final JAR file contains the other JAR files embedded within. Avoids dependency version clashes. All resource files are preserved.

How do you get source JARs from Maven repository?

Get sources and Javadocs – When you’re using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There’s an easy way to accomplish that goal.

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

The first command will attempt to download source code for each of the dependencies in your pom file.

The second command will attempt to download the Javadocs.

Maven is at the mercy of the library packagers here. So some of them won’t have source code packaged and many of them won’t have Javadocs.

In case you have a lot of dependencies it might also be a good idea to use inclusions/exclusions to get specific artifacts, the following command will for example only download the sources for the dependency with a specific artifactId:

mvn dependency:sources -DincludeArtifactIds=guava

Difference between maven scope compile and provided for JAR packaging?

I am trying to set up a project using Maven (m2eclipse), but I get this error in Eclipse:

Description Resource Path Location Type Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:2.0.2 from https://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:2.0.2 from/to central (https://repo1.maven.org/maven2): No response received after 60000 ExampleProject Unknown Maven Problem

Any ideas? It would be helpful if you could show me how to check if everything is configured fine…

A) Remove all your failed downloads:

find ~/.m2 -name “*.lastUpdated” -exec grep -q “Could not transfer” {} ; -print -exec rm {} ;

For windows:

cd %userprofile%.m2
epository
for /r %i in (*.lastUpdated) do del %i

Then rightclick on your project in eclipse and choose Maven->”Update Project …”, make sure “Update Dependencies” is checked in the resulting dialog and click OK.

What is the difference between Jenkins and Maven?

Maven is a build tool, in short a successor of ant. It helps in build and version control. However Jenkins is continuous integration system, where in maven is used for build. Jenkins can be used to automate the deployment process.

What are Gradle and Maven?

Gradle is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.

What is the use of Maven in Selenium?

Maven is a build automation tool which is distributed under Apache Software Foundation. It is mainly used for Java projects. It makes build consistent with another project. Maven is also used to manage the dependencies.

What is Maven JXR?

Maven JXR project (formally Java Cross Reference) is a library to analyze a set of Java source files and produces documentation in HTML format.

What is the default value for the packaging element?

Valid packaging values are some jar, war, ear and go. If the packaging value is not specified, it will automatically run to the jar.

What is the full name of a project?

<GroupId>: <artifactId>: <version>

What is a prohibition?

Any sort of relativity can be removed using the “delete” element. For example, A and C are excluded C because B and P are dependent on C.

What is the central repository of Maven?

Maven is a repository of words, which can easily be used in all projects, library jar, plug-ins or any other definite art galleries. The Maven Storage is of three types.

What is the use of Settings XML in Maven?

A maven settings.xml file defines the values that configure the Maven function in different ways. Usually, it is used to define a local storage space, alternate remote storage servers, and authentication information for individual repositories.

What’s Maven Central Gradually?

A module dependency generates the output of a particular function on a module behalf. Volumes are usually stored in a repository, such as Maven Central, a corporate maven or repository or a directory in a local file system.

Is Maven available to Java?

Ungrounded objects can be challenged and removed. Maven is primarily an automation tool used for Java projects. Maven will store Java libraries and Maven plugins in one or more repositories as a central repository and store them on a local cache.

How to override the default name of the war file ?

You can use the element <finalName></finalName> in your pom.xml file to override the default name of the war file.

What compile type scope ?

If we use compile type scope, then those dependencies will be available during the project build, that is when the classes are compiled, tests are compiled, when the tests, applications run.

What happens when we declare dependencies under the scope provided ?

It means that those are the dependencies which are required during build test and run but they are not required to be exported, meaning they need not be part of the application when it is deployed.

Explain about the parent pom file.

We can use the maven parent pom file to call the other modules.

Expain about the maven settings.xml file?

It contains the below configuration

Prody configuration
Local repository configuration
Remote repository configuration
Central Repository configuration

In which way the dependencies jar files are downloaded from net.

<> First it will the jar in local, if available it will take from local and compile the code.
<> If the jar is not available in local repo, then it will got central repo and download the jar and will compile
<> It the jar is not available in central , it will go remote repo and download the jar and compile the code .
<> If the jar is not available in three places, maven will failed the build.

what is GroupId refereces?

GroupId is nothing but reverse domain access and it will referes which file location

what is ArtifactsId refereces?

ArtifactsId is nothing but file name to download in accessed domain and it will referes file name.

what is Version and Scope refereces?

Version which defines the version control and scope which referes the file name.

Maven differentiation with Selenium webdriver?

<> In selenium web driver, invalid jar files are added to the project as library files, whereas in maven the jar files are added as dependencies.

<> In Selenium Web driver, for every individual project, it is essential to add all the jar files again to the new project, whereas this can be overcome by using maven by adding a pom.xml file to the new project.

How to exclude dependencies?

By using the exclusion element. Exclusions are specific dependency in your POM, and are targeted at a specific groupId and artifactId.

Processes involved in achieving the project?

Maven helps in creating a Java-based project more easily. Accessibility of new feature created or added in Maven added to a project in Maven configuration.

what is clean, default and site in maven?

> Clean represents cleans up artifacts achieved by previous builds.
> Default (or build): this can be customized to build the appliance.
> Site: generates site level documents for the project.

how does test and package phases implies in maven?

Test − the compiled source code involves the appropriate unit testing framework and these tests not required the code deployed or packaged.

Package − take the compiled code and package in a particular format like a JAR.

What is balm?

The project object refers to the POM model. This is the base unit that works in Maven. This is an XML file. It always lives as a pom.xml in the base directory of the program. The project (s) contains information about the project used and the structure of various structures used by Maven.

What is a storehouse?

A directory that contains the compiled JAR file pom.xml file as a soft repository.
Maven is looking for dependents in the

barns
local repository
Central repository
Remote repository

Search
R4R Team
R4R provides Maven Freshers questions and answers (Maven Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Maven interview question set 2,Maven Freshers & Experienced Interview Questions and Answers,Maven Objetive choice questions and answers,Maven Multiple choice questions and answers,Maven objective, Maven questions , Maven answers,Maven MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Maven fresher interview questions ,Maven Experienced interview questions,Maven fresher interview questions and answers ,Maven Experienced interview questions and answers,tricky Maven queries for interview pdf,complex Maven for practice with answers,Maven for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .