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.
Related
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 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>
POM.xml
<!-- https://mvnrepository.com/artifact/nl.captcha/simplecaptcha -->
<dependency>
<groupId>nl.captcha</groupId>
<artifactId>simplecaptcha</artifactId>
<version>1.2.1</version>
</dependency>
Java build path Problems
Description: Resource Path Location Type Archive for required library: 'C:/Users/RAJAT/.m2/repository/nl/captcha/simplecaptcha/1.2.1/simplecaptcha-1.2.1.jar' in project 'wheelmonk' cannot be read or is not a valid ZIP file wheelmonk Build path Build Path Problem
The referenced jar is a valid jar on maven central repo, so this can be excluded as a reason. Please first check your jar file if it has actually been download correctly and can be opened by e.g. 7zip.
If anything is broken on this jar file delete it and re-resolve it.
If u already download or having the captcha.jar in the project folder or anywhere in your local storage,
mvn install:install-file -DgroupId=nl.captcha -DartifactId=simplecaptcha -Dversion=1.2.1 -Dpackaging=jar -Dfile=**your-path-to-jar***
Add to this command and run the IDE terminal or project path CMD to initializing the .jar file and came up with build success, Then u can build the project successfully.
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 downloaded a source jar file of OrientDB from maven repo, orientdb-source.jar. The structure is:
orientdb-source.jar/com/orienttechnologies/orient/core/...
/META-INF/...
I have installed m2e plugin. But I dont know to import this jar file as a maven project. I dont want to import this jar file as an external jar. Can anyone help me?
It sounds like you want to use/access this artifact within a maven environment.
If all you want to do is use the jar in your class path you should add the jar as a dependency in your project's pom file. You may also need to add the repository reference to the pom if the jar is coming from a private repository. Once your pom file is modified with the reference to the jar then you can select your project and click "Maven -> Update project dependencies". Maven will download the jar and modify your class path.
If you want to actually look at the source then look for a reference on the 3rd party's web site to the repository containing the source code. Use the appropriate Eclipse plugin (git, svn, etc.) to point to and checkout the version of the source.
If you want to import the jar on your project, put this on your <dependecies> tag in pom.xml on root of your project:
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb</artifactId>
<version>1.3.0</version>
</dependency>
From Maven Repository
This will import the jar on your project lib folder.
Anyway, if you want to modify code from this lib, you need to create a new Project with content of this jar. Package as jar on maven and put as dependencie.