File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes I can't make maven use my external jars I added to local repository Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "I can Watch "I can New topic

I can't make maven use my external jars I added to local repository

jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 70


I ran the "hello world" app without swt at cmd to println and it printed out the msg, so it can see my class in the jar. The syntax below is complaining about swt. It is interesting that I tried a few things:
1.) redindex the repository
2.) go to window show view and rebuild index. At first my jars weren't showing, and now they are.
3.) I started fresh with a new Maven project because the other one might be tainted, as I was newer at this.

I did a echo %M2_REPO% and it printed out the right location.

I did a manifest display with jar -tf my-app2-0.0.3-SNAPSHOT.jar

I ran install with no reportable errors.

C:\Users\mtdew3q\workspace\my-app2\target>jar -tf my-app2-0.0.3-SNAPSHOT.jar
C:\Users\mtdew3q\.m2\repository>java -cp my-app2-0.0.3-SNAPSHOT.jar com.thirdshi
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widge
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Layout
at$ Source)
at Method)
at Source)

at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.thirdshiftcoder.derbyApp.Table_Demo. Program
will exit.

my pom is here:

located in .m2
<settings xmlns=""

The path to the offending jar generating a msg. when I try to run my program absolute path to SWT is c:\Users\mtdew3q\.m2\repository\swt\swt\4.3.0\swt-4.3.0.jar. Of note, there was never really a version when that jar came from the web. It just said swt.jar. That was the right version, but from the web the version wasn't included in the file name.

I am at my wits end. I can't get maven to recognize that SWT is in the local repository. If I can't include it with build_path, how in the world can I get it to recognize it is HERE in the local repo? I am also confused because it says maven dependencies in my project but it seems to be doing nothing.

When I run this as a java project from within eclipse a shell with a tbl shows with my data from derby displayed.

I know I said I'd wait to post, but I have some time off for election day and tried to give it another whirl. I have fun doing this, but I need a little break through on this one to keep me going.

If I can get this to recognize the local repo, I will think this is the coolest thing since cold sliced pizza.

thanks A LOT for helping, if you can,

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

What are the contents of META-INF/MANIFEST.MF file in your my-app2-0.0.3-SNAPSHOT.jar ?

[My Blog] [JavaRanch Journal]
E Armitage

Joined: Mar 17, 2012
Posts: 989
If you are installing fine then maven is seeing your swt jar. Your problem is when running the program which doesn't involve maven at all.
Is your application going to be distributed as a jar? Where are you going to put the dependent jars that should be part of the classpath?
You can tell maven to generate a jar with an arbitrary classpath by adding manifestEntries to your maven-jar configuration. This will result in a jar that may or may not work depending on whether exists or not on the machine where it is run. So basically your maven seems happy, it's just your distribution of your application that you need to think about and plan and then tell maven how you want it done.
jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 70
Thanks JP and EA!

Hi, I just noticed something cool I didn't see before. I wasn't using the pom editor in m2 for eclipse. Now I figured out to get a repository and search for my jars from the repository. So now I have the repository the way I want it. There is a dependency tab and all my jars show up there. Before they weren't.

Now I don't to download and unzip 3rdparty jars very often.I know I have the jars and they are in the local repository so why can't I run the project from outside of eclipse?

oh well. I will keep after it and try to figure this out. I am going to try to search for a video on how to run a maven project from the command line. I think tonight I will relax and go book shopping and read manuals on the web. I just need to keep reading stuff. I am going to figure out how to deploy my app so I don't need eclipse open to run it.

Can't you use the local .m2/repository and have eclipse recognize all those jars when deploying the app? I read about one jar but I noticed the xml is different and the one jar sample article was old with maven.

I don't have a very high level of using tools. For instance I just learned jar -tf or jar xf. That way I could check the manifest file contents after extracting the files.

Have a very cool Wed.

thanks so much,
jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 70

Thanks for sticking with me. I looked at the manifest as one poster asked, and I saw that all the dependent jars were included, so I dumped all the dependent jars in a directory and added the jar in target maven makes in that same directory. Now I am getting a different error msg. but it is because for a different reason. I think soon I will be running the app.

my cmd line to run is c:\Users\mtdew3q\.m2\repository\xf> java -jar myapp-version.snapshot.jar com.thirdshiftcoder.derbyApp Table_Demo

This is very cool.

jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 70
Here is my manifest contents: (thanks for the idea JP)

Manifest-Version: 1.0
Built-By: mtdew3q
Build-Jdk: 1.7.0_45
Class-Path: hibernate-core-4.2.7.Final.jar javassist-3.18.1-GA.jar jbo
ss-transaction-api_1.1_spec-1.0.1.Final.jar hibernate-jpa-2.0-api-1.0
.1.Final.jar hibernate-commons-annotations-4.0.2.Final.jar hibernate- ehcache-1.2.3
.jar commons-logging-1.0.4.jar asm-attrs-1.5.3.jar cglib-2.1_3.jar as
m-1.5.3.jar commons-collections-2.1.1.jar persistence-api-1.0.jar dom
4j-1.6.1.jar xml-apis-1.0.b2.jar jboss-transaction-4.2.2.GA.jar javas
sist-3.12.1.GA.jar antlr-2.7.7.jar derby- slf4j-simple-1
.7.5.jar slf4j-api-1.7.5.jar jboss-logging-3.1.3.GA.jar fabric3-jpa-h
ibernate-2.0.1.jar fabric3-monitor-log-2.0.1.jar jta-1.1.jar swt-win3
Created-By: Apache Maven 3.0.4
Main-Class: com.thirdshiftcoder.derbyApp.Table_Demo
Archiver-Version: Plexus Archiver

It is a little messy and I will have to figure that out later.

E Armitage

Joined: Mar 17, 2012
Posts: 989
Just keep in mind that maven is intended to help while you are developing your application and while assembling your target (runnable) artifact.
It is not intended to help with starting or running the application. Depending on who your application users are, they may not even have maven installed. So where to put the dependencies for running your application will depend on how you intend to distribute your application to the end users which you haven't specified yet.
jim mcnamara
Ranch Hand

Joined: Jun 13, 2007
Posts: 70
Hi- E. Armitage -

Thanks for all your help E. Your the best! I am learning to deploy now and from your tips figuring out where m2 plug-in and maven fit in. It is very cool to use. I really did like fatjar with onejar but fatjar was always so slow. I think this way is faster. I like how you can select from more than one repository and can also install 3rd party jars from the command line to the repository for those ones you need that aren't available in the repository. I did that with something I couldn't find elsewhere after using 2 repositories. I believe it was a jpa jar for hibernate. JPA was a requirement for deploying my hibernate app, but I couldn't find the right jar in the maven of jboss repo.

I am so glad I stuck it out. There was one night that nothing went right, and a few expletives were abound, but then I put on my rally cap.

Very cool.

I agree. Here's the link:
subject: I can't make maven use my external jars I added to local repository
It's not a secret anymore!