-2

How can i create a jar of a java project which contains src/main/java and src/test/java with dependencies using maven.

Note:test cases should not be run at the time of jar creation.

i have used this mvn clean compile assembly:single to generate jar that generates jar contains only src/main/java and dependencies but not src/test/java.

can any one please tell me how can i resolve this problem.Is the problem due pom file.What should i mension in pom to get.

my project structure looks like this:

enter image description here thank you

4
  • This is the way Maven works. Why should test classes be delivered in the JAR file? Sep 25, 2014 at 6:06
  • i need to run selenium testcases on different machines by copying this jar
    – hgchhgc
    Sep 25, 2014 at 6:12
  • Did you ever look into the documentation of the Maven JAR plugin? There you will find your answer. In fact, you should better read more documentation prior to asking questions. Sep 25, 2014 at 6:15
  • yes.when i add maven goal as jar:test-jar then run it will not generating test classes
    – hgchhgc
    Sep 25, 2014 at 6:34

2 Answers 2

1

You can use..

mvn clean install -DskipTests

I think you don't have dependency package plugin. Add this in your pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
  </plugin>
2
  • thank you .but this command does not include maven dependency jars
    – hgchhgc
    Sep 25, 2014 at 6:14
  • thank you.it creates me 3 jars.can't we make a single jar or main and dependencies one jar and test cases other jar
    – hgchhgc
    Sep 25, 2014 at 6:45
-1

Why dont youput your program into eclipse then

File->Export->Java->Runnable JAR file-> Save Location-> finish 

your jar file will be in the save location.

1
  • i know this but i want to automate this process with out manual export
    – hgchhgc
    Sep 25, 2014 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.