javamavenmaven-archetypearchetypes

How to use a maven project jar in a normal java project


I've converted a maven project to a jar and now, I'm trying to import this jar to the library of a new non-maven project.

I've tried to write main method on my own in order to call the maven jar classes (I'm a beginner to maven, so I don't know if this is possible). But it didn't work. And even though in the pom.xml, the packaging is set to jar, no jar is created once I install that maven project. So, using INTELLIJ, I exported the jar using the project structure tab. This is the pom.xml

<modelVersion>4.0.0</modelVersion>
    <groupId>com.google.code.jscep</groupId>
    <artifactId>jscep</artifactId>
    <packaging>jar</packaging>
    <version>2.5.5-SNAPSHOT</version>
    <name>jscep</name>

My requirement is "I need to write a java code using this maven project as library". So my question is 1) If I create a new project, should it need to be a maven type in order to use that "maven jar" or please tell me, if there's any way to create a non-maven project and use this "maven jar".

Or please guide me based on my requirement. Thanks


Solution

  • You can use the maven jar plugin to create a jar right from maven: https://maven.apache.org/plugins/maven-jar-plugin/

    You can add any jar as a dependency to a non-maven project. For IntelliJ, refer to this answer: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project