Hi from past 3 days i have been looking for a solution for my requirement but not getting help it will be great if someone can give me an idea how to go about it
my requirement:
i have source code in git in below structure:
Toolcode
- sources
- src
- main/java/.*java
- main/resources
-lib
- all dependencies like log4j etc
i want to fetch this code on my local machine and then refer the src and lib folder and build the code and package it as jar and place in a new folder called LIB and finally zip this folder LIB .
Can this be done using one single pom.xml file?
maven 3 build type does this
<modelVersion>4.0.0</modelVersion>
<groupId>projectgroup</groupId>
<artifactId>projectname</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
use this in pom.xml all this is done while creating project itself
Below pom.xml
would build as you which. With mvn package
you can generate a Jar file ./lib/Toolcode-1.0-SNAPSHOT-with-dependencies.jar
which contains all dependencies.
As long there is not a compelling reason to do so I would propose to use the Maven standard directory structure.
structure of directory Toolcode
before build
./pom.xml
./sources/src/main/java/sub/optimal/toolcode/Main.java
class
and jar
files created by mvn package
./lib/classes/sub/optimal/toolcode/Main.class
./lib/maven-archiver/pom.properties
./lib/Toolcode-1.0-SNAPSHOT-with-dependencies.jar
./lib/Toolcode-1.0-SNAPSHOT.jar
pom.xml (for non default directory structure)
<?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>sub.optimal</groupId>
<artifactId>Toolcode</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>
<build>
<directory>${project.basedir}/lib</directory>
<sourceDirectory>${project.basedir}/sources/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/sources/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/sources/src/main/java/</compileSourceRoot>
</compileSourceRoots>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<quiet>true</quiet>
<verbose>false</verbose>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.build.finalName}-with-dependencies</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.