This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 5 years ago.
I have a Maven project with certain set of dependencies. One of the dependencies is:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.0</version>
</dependency>
As long as I work in Eclipse, all is good. But when I package and try to use the resulting jar file(from command line if that matters), I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/NativeLibrary
while this class is definitely accessible in IDE.
My guess is that Maven is not packaging project's dependencies by default but in that case why don't I get more error messages complaining about more classes that were not found?
Maven will only create a jar for your project/component. This does not include the external jars (dependencies). If you want/need to include the contents of the dependencies in your jar, you should create a fat jar or uber jar. For an uber jar, you may use shade plugin.
Related
This question already has answers here:
Module error when running JavaFx media application
(2 answers)
Closed last month.
This post was edited and submitted for review 26 days ago.
I am new to Maven. I need to include
private javafx.embed.swing.JFXPanel jFXPanel1;
To a new project with uses Maven + Jigsaw modules.
I have the following problem with javafx.embed.swing package.
I thought that adding this dependency would work, but it does not.
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-swing -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>19</version>
</dependency>
On clean install, I see the following
(package javafx.embed.swing is declared in the unnamed module, but module com.my.module does not read it)
I don't understand this. I see that JAR, it only has a manifest file, and no .class files, which confuses me even more.
If I look in the m2 folder, I see a different JAR with the same prefix, but with win suffix and there I see the package.
I think this is the classifier
<classifier>${javafx.platform}</classifier>
And I think, but I don't know, if this jar is being picked by Maven or not, but it seems it is not, because I don't see it in the IntelliK libraries.
I don't have any problem with JavaFX, everything is modular out there and is working. I have the problem only with this jar.
-----------------------------UPDATE-----------------------------------
The culprit here was IntellijIdea i did click on File->Invalidate caches later restart it. Later i could see the dependency loaded.
Later i could add the module
And i can see now the dependency and that's it. Thanks.
Just declaring a Maven dependency is simply not enough. You also have to make the Java module system happy. You have to declare this additional dependency in your module-info.java file of your project too. Javas module system knows nothing about Maven dependencies.
This question already has answers here:
"cannot find symbol" error in maven
(5 answers)
Closed 4 years ago.
I am trying to package a SpringBoot project of mine to use as a library in another. I had it working somewhat but not I can't get my library classes to resolve at all.
I don't get any errors to do with the dependency in my POM file. I simply can't get to my library in my code.
I am building my package then installing it in my local Maven repo with mvn install:install-file -Dfile=myPackage.jar When I navigate to my local repo, the package is there and the pom file looks right. I bring it in to my project with
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>mylib</artifactId>
<version>0.0.1</version>
</dependency>
which all matches the POM for the package in the maven repo. I update the project configuration and no issues are found in my project POM. But com.mygroup.mylib is simply not found.
It seems that Maven is finding the dependency but for some reason the classes can't be found within it.
What are some ways to get more information about where the disconnect is?
I am using spring boot 2.0.0 and VSCode 1.20.1.
Run maven command for logs to find out actual issue.
mvn clean install -X
This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 6 years ago.
I have 50 jars that I need to add to a Maven project as dependencies. They are not in the public repository, I cannot install a local repository and I'd like to know a quick solution to add them in my pom.xml.
I know that to add a local dependency you could write
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
but this is simply a real long task with several Jars. Is there an easy way to do it?
The solutions suggested in How to add local jar files in maven project? are specific for a single or few Jars but not the case when you many of them.
Add those jars to your local maven repository and then add their dependency to your POM. See this link: MKYong: How to include custom library into maven local repository?
This is the first time I am using maven, I want to implement a processor for apache-nifi. Now for this I am using a proprietary jar file which is an SDK. It is not on the repositories. Therefore i have put it in the pom.xml as follows.
<dependency>
<groupId>KS</groupId>
<artifactId>En-SDK</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/En-SDK-Java.jar</systemPath>
</dependency>
I am using intelliJ which seem to have no problem importing this dependency. So is the maven build procedure.
I use mvn clean install as explained in this tutorial. Which gives me with a nar package as the output. (no build errors)
This nar , which is supposed to be put in the $NIFI_HOME/lib directory does not bundle the said local jar.
If i place this nar file in the required directory and start apache-nifi,
INFO [main] org.apache.nifi.nar.NarClassLoaders Loaded NAR file: /..././work/nar/extensions/myNar.nar
Seems to be loaded by the NarClassLoaders , but following that I get an exception and nifi doesn't start.
java.lang.NoClassDefFoundError: com/kls/../../SubscriptionInterface
The SubscriptionInterface is a class from the said local jar.
If I look at the nar file's folder structure, inside the META-INF/bundled-dependencies/ i see every other dependant jar files defined in the pom but not this local jar i used.
How to overcome this?
The following Stackoverflow question seems to be similar to what you have asked.
Maven 2 assembly with dependencies: jar under scope "system" not included
Try to put the dependency in a local repository and declare it in the pom.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Maven: add a dependency to a jar by relative path
I need import a .jar file using only a buildpath in a java maven project without creating a dependency. Can this be done?
You mean that your jar is used only to compile but is not a transitive dependency?
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
provided:
This scope is only available on the compilation and test classpath, and is not transitive.
See more on dependency scopes