How to generate maven jar that will include my external jars that under lib folder - maven

I have maven project with lib folder that contains some jars,
In my pom.xml, I've added dependency accordingly like:
<dependency>
<groupId>autoit</groupId>
<artifactId>autoit</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/AutoItX4Java.jar</systemPath>
</dependency>
The problem is when I create a jar and run on cmd I get Exception:
nested exception is: java.lang.NoClassDefFoundError :
AutoItX4Java...
If I run via eclipse there are no Errors.

Related

java.lang.NoClassDefFoundError: org/json/JSONObject in customised jar file

I created a jar file that using customized JSONObject class when I include it in my project in pom.xml i am getting the above error. When i import it using IntelliJ it only works in IntelliJ but I wasnt to share the jar file. How can I make my customized file be incorporated with the project?
<dependency>
<groupId>com.roufid.tutorials</groupId>
<artifactId>example-app</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/yourJar.jar</systemPath>
</dependency>
This is what I did
Run below command in project root (the location that contains `pom.xml file)
.\mvnw install:install-file -Dfile='src\lib\custom.json.object-0.1.0.jar' -DgroupId='com.custom.json.object' -DartifactId='com.custom.json.object' -Dversion='0.1.0' -Dpackaging=jar
In pom.xml I added the below line
<dependency>
<groupId>com.custom.json.object</groupId>
<artifactId>com.custom.json.object</artifactId>
<version>0.1.0</version>
</dependency>

Adding runtime dependency jars with maven

Is there a way to include runtime dependency jar to maven project. Basically I want to include project1 as dependency jar at runtime to project2.
Project1
src/main/java
com.test.example1
Project2
src/main/java
com.test.example2
lib
I received error - 'dependencies.dependency.systemPath' for com.test.example2.PublishItem:jar must be omitted. This field may only be specified for a dependency with system scope
<dependency>
<groupId>com.test.example2</groupId>
<artifactId>PublishItem</artifactId>
<scope>runtime</scope>
<version>1.0-SNAPSHOT</version>
<systemPath>${project.basedir}/src/main/java/lib/</systemPath>
</dependency>

Maven local dependency isn't working: ClassNotFoundException

I have a Maven Web project made in netbeans and I have a local dependency:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sqljdbc4.jar</systemPath>
<optional>true</optional>
</dependency>
That dependency works perfectly if I run the project over Apache Tomcat 6.0 but I have some class that I run on demand (main method) and when I try to run the class I get this exception:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
Try this (it works for me)
Get rid of the maven dependency, and the jar from the lib (we'll have it automatically added)
From your project, right click on the "Dependencies" -> "Add Dependency"
In the dialog, type the coordinates for the groupId, artifactId, version, click ok
This will leave an unresolved jar in the dependency tree.
Right click on the jar from the "Dependencies", select "Manually Install Artifact". Locate the artifact and add it, and "Install Locally". This will install the jar to the local repo. Also since its a webapp, the jar will get sent to the lib like it normally would
Now you should be able to run it.

maven assembly how to add a zip flie from nexus repository to the build

I am trying to include a zip file from nexus repository to my project during packaging using the maven assembly plugin. This zip file has YAJSW and other custom scripts. The maven assembly can build a tar.gz package now, but how do I include a zip file from nexus repository. There is a pom for that zip file. Should I just include that as dependency? Is this the correct plugin or should I use another plugin.
Thanks.
Add the dependency of the zip file like the following:
The following is an example for archive which has been created by maven-assembly-plugin:
<dependency>
<groupId>the.group.id</groupId>
<artifactId>the-artifactid</artifactId>
<version>1.0</version>
<type>tar.gz</type>
<cassifier>bin-unix</classifier>
</dependency>
<dependency>
<groupId>the.group.id</groupId>
<artifactId>the-artifactid</artifactId>
<version>1.0</version>
<type>zip</type>
<cassifier>bin</classifier>
</dependency>
The classifier in those cases is comming from the assembly-decscriptor-id in the project which creates the archive. Apart from that it is important to define the type.
Add a dependency to the zip with the respective GAV (group/artifactId/version).
(Without seeing your pom.xml it's a bit hard to say more).

Maven - Unable to resolve dependencies

Im trying to compile a Maven project. The compile fails however due to a "Failure to find xx.xxx.jar" in the repository i have specified in my settings.xml. I have access to this repository and when i navigate to the Url of the repository maven is trying to use i can see a pom file with the name of the jar but no jar. When i open the pom it contains the correct groupid and artificatid and jar name however the jar is not in the same directory.
Maven gives another error saying that "resolution will not be reattempted until the update interval of my repo-server has elasped or updated are forced".
What is happening here?
When maven goes to the repo i specify in settings.xml and finds a pom for the jar does it then try and go out to some external site to resolve the dependency or should the jar exist in the same folder as the pom?
What module are you attempting to download?
I discovered something similar with the following Maven central module:
http://search.maven.org/#artifactdetails|net.sf.json-lib|json-lib|2.4|jar
The Maven POM packaging declaration was jar, but no jar in Maven called "json-lib-2.4.jar"
When I looked at the files actually stored, I discovered that the author is providing two versions of the jar, each compiled for different versions of the JVM:
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk13</classifier>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

Resources