And add the Maven Shade Plugin to create a full jar
(The name of this plugin is deceptive; it can shade, but the primary purpose is to build a jar that contains all your dependencies)
Add the compiler plugin:
Finally, execute "maven package" and it will generate a jar in the target folder which will be runnable and contain all your dependencies. This is the easiest and most consistent way to create jar files.
If you're trying to put JARs within JARs, that does not work in standard Java. Only classes in the outer JAR get put into the application's CLASSPATH.
If you want to include other JARs within an executable JAR, then you need to add some additional code to extend the CLASSPATH. The easiest way to do that is to let Maven build the executable JAR using its executable JAR mojo Maven will add the extra logic. Just a regulat Maven JAR build won't do that, however, so you do need to build with the correct mojo.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
The shade plugin that Zachary mentioned bundles the contents of all dependencies inside your own JAR, making it a so-called fat JAR. This will work without any other JAR files, because their contents are placed alongside your own classes.
R Nordstrom wrote:. . . This is the contents of MANIFEST.MF . . .
I presume it has an empty line at the end.
I do not see a Path-Class statement. Do I need one ?
Do you mean classpath? You only need a classpath if you are dependent on some external resources.
posted 3 weeks ago
If the other jar files are NOT inside of your jar file but are separate files that are in the same folder as your jar file, the Class-Path statement will allow the JVM to find and use them.
posted 3 weeks ago
I found a Class-Path line in a project jar from my NetBeans-8 projects.
This is what my manifest file contained:
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_40-b26 (Oracle Corporation)
Class-Path: lib/jssc.jar lib/jna-4.1.0.jar lib/commons-math3-3.6.1.jar
X-COMMENT: Main-Class will be added automatically by build
So now I need to figure out why Netbeans-10 is not adding this line, or modify my current project jar/manifest file.
I am not sure how to do either of these, but at least I know what is wrong.
posted 3 weeks ago
It looks like the Class-Path statement is telling the JVM to look in the lib folder for the 3 jar files on the statement. Your jar file would be in a folder that contained the lib folder.
posted 2 weeks ago
Hi Every one,
I figured out the root problem. Netbeans 9, 10 and early 11, have a bug. When the clean/build is executed it does not add the appropriate Class-Path line to the manifest file. Also it does not create the lib folder for your library jars. This problem was solved in Netbeans 11.2. By installing Netbeans 11.3 I now have a good command line launch in win7 and ubuntu 18.04.
Zachary Griggs wrote://truncated to avoid full post quote
Although the topic is solved there're several issues to address:
1) As the error message was not "could not find main class" but a classdefnotfound of a dependency the issue was obviously not caused by a missing main-class manifest attribut - so, why even mentoined it? Did you read and understood the problem? Or did you may only jzst copied in some pre-written default text of maybe many?
2) Although building a fat jar often at least "make things work" it's far from an ideal solution. Aside from possible conflicts it can be compared to keep swallow painkillers instead of taking proper meds to cure: you're just tinkering with the symptoms instead of fixing the cause.
This is the easiest and most consistent way to create jar files.
Uhm, no, it isn't. It's neither easy nor consistent and hence shouldn't be seen or used as such.
If you have an external lib within it's own jar don't mess with it but rather correctly reference it in the classpath.
Btw: This may work for a hobbyist dev - but most often licenses deny abusing their covered code that way on distribution. You just can't ship a big fat jar couple 100mb in size.
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Devious Experiments for a Truly Passive Greenhouse!