Generate source code jar for Maven based project

In this tutorial, we will see how to generate source code jar for maven based project.

If you have simple java project, then you need to convert it maven project.

Sometimes, you need to pack source code with your project jar. This is extremely useful when people use your library and can attach source code for debugging.

You can simply use maven-source-plugin to achieve the same.

Once you put this in your pom.xml, you should be able to see source jar along with your project jar.

Here is complete pom.xml.

Deploy the jar

You need to run mvn install to generate the source jar along with project jar.
I am using eclipse to run this mvn command.

You can also go to project location in terminal and execute mvn install to generate the source code jar.

Here is output of the command.

Check the local repository

You should be able to find jar file in maven local repository. Here is output of above command.

I was able to find source jar at this location.
/Users/apple/.m2/repository/org/arpit/java2blog/Java2blogMaven

That’s all about how to generate source code jar for Maven based project.

Related Posts

  • 21 March

    Install Maven on Mac

    Table of ContentsInstall maven manuallyDownload and extract MavenUpdate M2_HOME and PATHVerfiy maven installationInstall maven using Homebrew In this post, we will see how to install maven on Mac. If you are using the latest MacOSX, maven may be built-in and can be found at /usr/share/maven. Execute below command on terminal to see if you have […]

  • 21 March

    Run single test in maven

    Table of ContentsRun all testcaseRun all testcases from a test classRun specific test method from a test classRun multiple test methods from a test class In this post, we will see how to run single test in maven. If you want to execute all the Junit testcases in maven. You can run it below command. […]

  • 21 March

    Skip tests in maven

    Table of ContentsUsing maven.test.skip=trueUsing SkipTestsSkip tests in Maven in eclipseConclusion In this tutorial, we will see how to skip tests in maven. It is not a good idea to skip junit tests while building project in maven but sometimes, you may need to skip it for building new code and want to test it quickly. […]

  • 23 August

    log4j properties file example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 23 May

    log4j xml configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 20 February

    Log4j Maven configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.