1

Making a runnable .jar with dependent libraries for dummys..

Can someone outline the steps I have to take to making a runnable .jar with dependent libraries for dummy with Maven and Eclipse.

I want to use Maven to load the dependent jars but will be using eclipse to do all my coding.... can this be done? I started a projects but Eclipses does not see the dependent libs in my pom.xml file so I am getting errors as I am coding.

Here is my pom.xml

<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>org.runnablejar</groupId>
    <artifactId>RunnableJAR</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>RunnableJAR</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>fully.qualified.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

and I dont know why this code is giving me errors in eclipses

package org.runnablejar.RunnableJAR;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Hello world!
 *
 */
public class App 
{
    private static Log log = LogFactory.getLog(App.class.getName());

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}
techsjs2012
  • 1,737
  • 5
  • 25
  • 57

2 Answers2

2

You could either:

  1. Use the m2eclipse Maven plugin for Eclipse to make the project maven-aware,
  2. Use the mvn eclipse:eclipse maven goal to generate a proper .classpath file.
Xavi López
  • 27,550
  • 11
  • 97
  • 161
0

Google told me that this question could be helpful. It seems to point to the Maven Assembly Plugin. Is that what you are looking for?

Community
  • 1
  • 1
Pao
  • 843
  • 5
  • 17
  • i understand that part but how do I make eclipse see the JARS that I have in my pom.xml – techsjs2012 Sep 14 '12 at 22:28
  • See the jars? Maven should download the jars and put them in Maven Dependencies in Eclipse. – Pao Sep 14 '12 at 22:38
  • i can see them in the Maven Dependencies in Eclipse but I am still getting a error can you look at the pox and let me know if something is not right – techsjs2012 Sep 14 '12 at 22:40