Thanks for the engagement. I'm not following you, though. When I build the package shouldn't maven in reading pom.xml see my dependencies and retrieve/build whatever I need? I see no evidence of it having done that so I don't see what adding my local repo to the classpath would accomplish.
When you say "retrieve/build what I need", if you mean "put all the dependencies into one jar file", the answer is no. Maven builds the jar in a way that allows you to specify your library directory, so that your different projects can share library (jar) files. This library need to be in the classpath. If you want one, executable jar with all the dependencies in it, I think the best way is to use the Shade plugin. At least that's the way I did it. Here is the relevant part of my pom file:
All things are lawful, but not all things are profitable.
Here's the core question, forgetting about building a single fat jar file for now. Where is slf4j-api? I listed it as a dependency but Maven didn't retrieve it, or build it, or do anything with it as far as I can tell. So, I have no jar file to add to my classpath.
Aha! That explains absolutely everything! I didn't understand that maven creates one repository for all of my projects. Yesterday I had created a project and it downloaded opennlp for it. Today when I created a new project that uses opennlp it didn't have to retrieve it off the net because it was already there. And, I see the slf4j-api jar there. I've added it to my classpath.
Why are you creating a classpath (referencing your other thread)?
You have this in your pom:
You've asked Maven to produce an executable jar file, with the classpath included (well, the jar file names anyway).
If all the jar files are in the same place you could just add the classpathPrefix entry to stick the directory path in.
Dave, I was playing around with addClasspath but didn't get it to work. I do have a variety of jar files sprinkled here and there. I ended up writing a shell script with a long "java -cp" line that works for me. I use that script to launch the Java code.
Hmmm... There really only is the one project. It has dependencies on OpenNLP and SF4J. The jar file is in the Maven repository and the jar file has the right class in it. I'm going to give up on this and someday figure it out. I am able to run the code by adding the jar file to the "java -cp" command so I'm good.
I'm doing a superficial reading of this thread, so I may be getting it all wrong, but it sounds like the goal is to create an executable JAR.
An executable JAR that has dependencies (library JARs) has problems. That's because you cannot just include a JAR within another JAR. The JVM classloader won't look in those JARS - they are not part of the classpath, per the Java specs. Hence ClassNotFound and NoClassDefinition exceptions.
The way around that is to build a JAR that contains a custom classloader that will look inside embedded JARs. There is a Maven plugin that will do this.
It's a fairly common thing, so search this forum for "executable jar" and you'll probably find something useful.
Sources may include data from the Fakebook Research Foundation with support from Gargle University