snippetjournal

- notes, snippet codes, and my journal

ADD JAR OR LIBRARY TO NETBEANS MAVEN PROJECT.

leave a comment »

Yeah its really troublesome if u wanna add jars that are not supported maven in netbeans, the default dependencies in netbeans is to search in maven repo.

so if we want to add jar that not supported maven, we must install the jar to our maven local repo.

there is 2 way to add your jar to maven project in netbeans, first add it manually using maven command in console/cmd or the easier way, right click in your missing jar :)

Right click  in your missing jar in project explorer and browse your missing jar

 

netbeans - maven right click

 

netbeans- maven browse

 

Using maven command in your console/cmd

first we just using maven that already in netbeans installation package, the maven netbeans library is located in :

E:\Program Files\NetBeans 7.3\java\maven\bin

you can simply open command console in the maven path, or you can set up configure the maven in system variable, just add in the PATH variable in the system environment
note: split it between the path application using semicolon (;)

make sure that u have set up your java environment variable
JAVA_HOME add in system variable

JAVA_HOME = E:\Program Files\Java\jdk1.7.0_21\

open cmd, and install the jar file using maven,

mvn install:install-file -Dfile=F:\xx\xx\xx\jcprov-1.0.jar -DgroupId=safenet.jcprov -DartifactId=jcprov -Dversion=1.0 -Dpackaging=jar

note : notice that “-DgroupId”, “-DartifactId” and “-Dversion” value must exact the same as in pom.xml

command result :

C:\Users\xxx>mvn install:install-file -Dfile=F:\xx\xx\
xx\jcprov-1.0.jar -DgroupId=safenet.jcprov -DartifactId=jcprov -Dversion=1.0 -D
packaging=jar
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ————————————————————————
[INFO]
[INFO] — maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-po
m —
[INFO] Installing F:\xx\xx\xx\jcprov-1.0.jar to C:\xx\xx\.m2\repository\safenet\jcprov\jcprov\1.0\jcprov-1.0.jar
[INFO] Installing C:\xx\xx~1\AppData\Local\Temp\mvninstall987667663473993
863.pom to C:\xx\xx\.m2\repository\safenet\jcprov\jcprov\1.0
\jcprov-1.0.pom
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 2.393s
[INFO] Finished at: Mon May 27 10:48:02 ICT 2013
[INFO] Final Memory: 6M/112M
[INFO] ————————————————————————

yeay the jar successfully installed :D, and for the final step u can add the dependency in the pom.xml in netbeans project.

<dependency>
<groupId>safenet.jcprov</groupId>
<artifactId>jcprov</artifactId>
<version>1.0</version>
</dependency>

netbeans will auto refresh the project and it will no red error anymore…

references :

http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

About these ads

Written by snippetjournal

May 27, 2013 at 4:09 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 67 other followers

%d bloggers like this: