-1

I want to create a runnable jar using the below pom.xml and i dont get the expected jar. Please do the needful.

<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>testjar</groupId>
    <artifactId>testjar</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <url>http://maven.apache.org</url>
    <properties>
        <jdk.version>1.5</jdk.version>
        <lib>lib/</lib>
    </properties>
    <repositories>
        <repository>
            <releases />
            <id>repository</id>
            <name>repository</name>
            <url>file:///data/apps/dev/projects/maven/repository</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${lib}/log4j.jar</systemPath>
        </dependency>       
    </dependencies>
    <build>
        <finalName>testjar</finalName>      
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>testApp</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>                   
        </plugins>
    </build>
</project>
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
Karthick
  • 79
  • 1
  • 2
  • 7
  • Once you manage to build your JAR, you will need a custom classloader like [one-jar](http://one-jar.sourceforge.net/) to run a jar with jar-in-jar contents. Google for "uber jar" for an alternative approach. – Ralf Jan 07 '14 at 09:13
  • @Ralf not necessarily. For a simple app jar-with-dependencies is more than enough. – Nikola Yovchev Jan 07 '14 at 09:27
  • @baba I interpreted "with dependency jar **in it**" as jar-in-jar. – Ralf Jan 07 '14 at 09:51
  • @Ralf you can easily achieve that by using a combination of maven plugins. One jar is more likely than not to mangle a Spring application, for example, because of the way it treats resources files in different dependencies with the same name. That is why in order to build a complex app, you wouldn't use one-jar, but rather simpler plugins. In the op's case, jar-with-dependencies should be enough. – Nikola Yovchev Jan 07 '14 at 10:40
  • @Ralf: one-jar is working fine and i got the expected jar from it. One more question how i can change the jar name? – Karthick Jan 07 '14 at 10:53
  • I tried testjar.jar but the o/p jar generated is testjar.one-jar.jar. – Karthick Jan 07 '14 at 10:54

1 Answers1

0

Does the main class (testApp) exist? That doesn't seem to me like a correct fully qualified class name. If it is, it doesn't follow java class naming conventions (not really relevant to your question, but a very big giveaway of your current skill and knowledge).

Please indicate what you have tried and what problems are you facing.

Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72