• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi-

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
META-INF/
META-INF/MANIFEST.MF
com/
com/thirdshiftcoder/
com/thirdshiftcoder/derbyApp/
City.hbm.xml
com/thirdshiftcoder/derbyApp/City.class
com/thirdshiftcoder/derbyApp/Foo.class
com/thirdshiftcoder/derbyApp/Table_Demo.class
META-INF/maven/
META-INF/maven/com.thirdshiftcoder.derbyApp/
META-INF/maven/com.thirdshiftcoder.derbyApp/my-app2/
META-INF/maven/com.thirdshiftcoder.derbyApp/my-app2/pom.xml
META-INF/maven/com.thirdshiftcoder.derbyApp/my-app2/pom.properties
C:\Users\mtdew3q\.m2\repository>java -cp my-app2-0.0.3-SNAPSHOT.jar com.thirdshi
ftcoder.derbyApp.Table_Demo
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widge
ts/Layout
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Layout
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown 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="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>c:/Users/mtdew3q/.m2/repository</localRepository>
<interactiveMode>false</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>true</offline>
</settings>

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,
jim

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the contents of META-INF/MANIFEST.MF file in your my-app2-0.0.3-SNAPSHOT.jar ?
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 path.to.the.swt.and.other.jars 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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HOORAY!

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.

THANKS
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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-
commons-annotations-3.3.0.ga.jar hibernate-3.2.1.ga.jar 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-10.10.1.1.jar 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
2-3.0m8.jar
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.

thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic