I have a local Jar file that I want to add as a dependency for a Maven project that I am working on.
That is easy to do as this answer states.
The problem is that this Jar file requires a foo.classifier file to work properly.
This Jar file is meant to be run by command line (java -jar bar.jar {argument}). The Jar and the classifier files are in the same directory, so everything works just fine.
However, from my project, I want to call the Jar file using its methods and not running a process.
I added the Jar file as a dependency and managed to call the main method that receives the argument, however, it doesn't work properly because of the foo.classifier the file is not set as a dependency for that Jar file to work.
Does anyone know how can I set it as a dependency of that Jar file?
Put foo.classifier files in exact folder in .m2\repository folder where your local Jar file that you added as a dependency is present as dependency jar will be referred from local repository
You can put your jar to libs directory,and add below code into your pom.xml file:
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.21-OSGi</version>``
<scope>system</scope>
<systemPath>the full path of the jar</systemPath>
</dependency>
Add the jar to maven repository with the follows command line, specify a group id, artifact id and a version
mvn install:install-file -Dfile="my-local.jar" -DgroupId="my.groupid" -DartifactId="name" -Dversion="1.0.0" -Dpackaging=jar
and then add as dependency to your pom
<dependency>
<groupId>my.groupid</groupId>
<artifactId>name</artifactId>
<version>1.0.0</version>
</dependency>
Related
I have a simple maven project where I have a simple class analyzing File encoding. I am using the juniversalchardet library from Google juniversalchardet library . In the pom.xml I added the dependency from link above. When I build the project with mvn clean install, everything looks fine. In the local repository I see tha universalchardet.jar file also. The class file in my project is also compiled without errors. But when I run my project .JAR i get an error like this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/universalchardet/UniversalDetector
Here is my dependency:
<dependency>
<groupId>com.googlecode.juniversalchardet</groupId>
<artifactId>juniversalchardet</artifactId>
<version>1.0.3</version>
</dependency>
I am not very familiar with Java - what I am doing wrong?
You can try this https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
where you mention your dependency jar in your manifest file : Class-Path: juniversalchardet.jar
Or
Consider making your jar as uber jar, refer: What is an uber jar?
I have a situation like below:
1. I have a JAR which is available in cloud URL
2. I want to download the JAR and use it as a JAR in my project.
3. For downloading I am using Maven ant run plugin and putting it in specific folder of the project.
Now I want to add the jar to classpath file via pom.xml
I have downloaded the JAR from the cloud and placed it in specific folder.
Is there anyway in which as soon as I download the JAR from cloud, I can modify my classpath by adding a classpathEntry through POM.xml?
There are various ways but the easiest option is to download the file to your local repository with the file path matching to your dependency's groupId, artifactId and version.
Assuming below is the dependency that you are trying to add to you pom.xml
<dependency>
<groupId>your.company</groupId>
<artifactId>downloaded-file</artifactId>
<version>1.0.0</version>
</dependency>
then download the file to /your/company/downloaded-file/downloaded-file-1.0.0.jar
I have a maven based project where I have to invoke an external jar (say country.jar)
I added this jar on src/lib folder and did below setting in pom.xml
<dependency>
<groupId>country-stubs</groupId>
<artifactId>country-stubs</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\country.jar</systemPath>
</dependency>
While Running my application I am getting error
java.lang.NoClassDefFoundError: com/fsg/bpo/webservices/countWebService
Location(com/fsg/bpo/webservices/countWebService) is referring to the class present under country JAR
Do I need to add few more settings to configure external JAR in maven ?
If you are using scope system you are saying it is a provided jar later on. I would use runtime maybe. Have a look at maven scopes
If it is web application then your jar won't get bundled inside your war file. Then you will get this issue. you can directly copy this country.jar to your WEB-INF lib folder and use that system path.
1st u need to add ur external jar to ur local maven directory..
using below command on cmd..
mvn install:install-file -DgroupId= -DartifactId=aes-decryption -Dversion=1.0.0 -Dpackaging=jar -Dfile=./target/aes-decryption-1.0.0.jar -DgeneratePom=true
I have a Maven project converted from a Java project.
My project structure only contains one folder for sources (/src) and doesn't look like a standard Maven project which creates /src/main/java and /src/test/java folders.
I'm trying to add a resource to this project. The resource will be pulled from Nexus and it is a zip archive that contains an .exe file. I've added the following into pom.xml:
<dependency>
<groupid>group.id</groupid>
<artifactid>artifactid</artifactid>
<version>1.0</version>
<type>zip</type>
</dependency>
The resource (zip file) is downloaded in .m2/repository/.../.../. I would need a way to access the resource (unzip it and run the .exe file) and also, I would like this resource to be embedded in the .jar file that I'll export.
Basically, I want to embbed an external .exe file into a .jar file and be able to execute it. The .exe file is stored in an acrhive on Nexus.
Is there any way to achive this?
Thanks!
To grab and unzip an artifact, simply use the mvn dependency:unpack goal (No need for dependency here, but it might be implied)
https://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
To execute an executable, use the mvn exec:exec goal
http://mojo.codehaus.org/exec-maven-plugin/exec-mojo.html
I don't understand your final requirements, but I hope the above helps.
I am using maven to build my java project.
I have a library jar named my.jar used as my project's dependency. However, it is not available in the remote central repository. So, I would like to put the jar file under my project. So, I created a folder named my_repo/ under MyProject.
The directory structure of MyProject looks like this:
MyProject/
my_repo/
my.jar
pom.xml
But I have no idea how could I define my pom to find this particular dependency under MyProject/my_repo/my.jar ?
Could someone please help me for my scenario? By the way, I have also some other dependencies defined in my pom.xml, they are available in the remote central repo.
Using the system scope. ${basedir} is the directory of your pom.
<dependency>
<artifactId>..</artifactId>
<groupId>..</groupId>
<scope>system</scope>
<systemPath>${basedir}/my_repo/my.jar</systemPath>
</dependency>
The recommended way is usually to use a Maven Repository Manager (e.g. Nexus) and then deploy your library to this Maven Repository Manager.
See here for how to set up the settings.xml file:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
How to create maven dependency for your local jars..
1)Create a maven project of the program of which you have to create the jar.
2)Add required groupid and artifact id and version no.
3)Then after writing the java files export it as a jar.
4)Now open other project in which you want to add local jar dependency.Go into its pom.xml and add dependency with the group id,artifact id and version which u had entered in the jar project.
5)Maven clean and install.Now that jar file will be available in your local repository. :)