Alexander Mills
Alexander Mills

Reputation: 100010

How to create a Maven library (non-executable JAR)

I am looking for a Git repo that I clone and get started on creating a simple library for Java/Maven. I assume I need to declare a mainClass which will be the interface to the library but I don't need to declare a main method? It's stupidly difficult to figure out how to create a library with Maven, I should be able to just clone a git repo skeleton project that has most things pre-configured?

So my question is - does anyone know of a good repo to clone that is a Maven library skeleton? Note that I not looking to create Maven plugin - just a library that uses Maven for dep management.

Upvotes: 5

Views: 21668

Answers (2)

JosemyAB
JosemyAB

Reputation: 407

I have upload this repo for you. Its a very basic skeleton. Hope it helps you.

Basically it is a simple folder structure..

maven-library-skeleton
|
- src
     |
     - main
           |
           - java
- test
- pom.xml

pom.xml content is:

<?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.empty</groupId>
   <artifactId>maven-library-skeleton</artifactId>
   <version>1.0.0-SNAPSHOT</version>

   <name>${project.groupId}:${project.artifactId}</name>
   <description>Empty library</description>
   <packaging>jar</packaging>

   <dependencies>
      <!-- Your required dependencies here! -->
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
               <encoding>UTF-8</encoding>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

You can then simply build the library with mvn package.

Link to repository is: https://github.com/JosemyAB/maven-library-skeleton

Upvotes: 8

Kurt Risser
Kurt Risser

Reputation: 29

The <version>1.0.0-SNAPSHOT</version>> has an extra right angle bracket that will result in error.

Upvotes: 2

Related Questions