Creating a Jar file:
I want to create Jar files from a Github Java repository. How can I create below Jar files?
Jars to create:
geo-ip-java.jar
hive-udf-geo-ip-jtg.jar
Git URL: https://github.com/edwardcapriolo/hive-geoip
I found we can create them as below syntax, but seems it is using maven to compile them:
jar cf jar_file.jar file.java
As this is a maven project (as seen that the file pom.xml exists) you can create the target artifact (in your case the jar file) by simply executing mvn package.
If you want to use the jar file in another maven project (as dependency) then it is more usefull to use mvn install as this also installs the artifact in your local repository.
Related
Code : https://github.com/efsavage/hello-world-war/blob/master/pom.xml
Here in POM.XML file there is war which is as required.
Now, I am building project using below CLI commands
mvn clean
mvn install -Dpackaging = jar
Output required to get jar file for a project whereas it is creating the war file due to given war plugin in pom.xml.
Any idea on how can we generate jar file by using only cli , not updating the pom.xml from the given link.
I have a Maven project where I've imported an external JAR (via Build Path) and it's under Referenced libraries folder. How can I import it within my .java class file? I mean literally the code "import ??". The class is in com.example.demo package. Do I need to add a dependency somewhere (pom.xml)?
If that's a maven project the best way would be to add that jar as a dependency in your pom.xml dependencies section. Then when you compile with maven it will use that dependency. In order to build properly in eclipse you need to call mvn eclipse:eclipse and it will sync the dependencies in the pom.xml with the build paths of the eclipse project.
If the jar is not a common one and you cannot add find it in the public repo (for example some jar that you have created) then you need to first install it in your maven repository with the required group and artefact name. Otherwise if it is some library which is publicly available in the central maven repository maven will download the required jar and install it in your local repository for you
I am using maven to build my project, I also have some .jar libraries that I cannot include in my POM because I don't know their arifact and group IDs. Is it possible to add a directory as a repository, or just reference them in my pom in another way, so that when I export .war file they get packaged?
I am trying to update a class file in a jar Apache Maven.
Jar was compiled originally with 1.8.0_05 jdk. How can I compile it in order to be compatible with the jar?
You'll need to identify where your repository is located. It might be in your C:\users\{userprofile}\.m2 folder or it might be in a central location set by your Enterprise (and referenced in your project through an environment variable).
Under that repository folder is stored all JARs and POMs. You can find the location of the JAR you are looking for by looking at your project POM file and finding the groupID for that artifact. Once you find the one you need, you just extract it, make your changes, recompile and put it back and the run a mvn clean install on your project folder (where your main POM file is).
I would like to do the following with the maven:
Pack my code & dependencies to uber jar
Attach a script to it (either Windows script or Linux script)
Put both script and jar to a folder
Crate zip for Windows AND tar.gz file for Linux
Is this possible in Maven using assembly or any other plugin?
i would split this into two projects and for convenience a parent module, like this:
projectX
|- codeproject
|- packingproject
\- pom.xml
codeproject:
Nothing special here, just create your über-jar
packagingproject:
save your scripts as src/main/resources/start.bat
copy your codeproject.jar with copy-dependencies
create your zip/tar-file with the maven-assembly-plugin
parent pom:
also, nothing special, just add both modules
Note:
be sure to call install on your codeproject so that the jar gets copied to your local maven repository, otherwise you may end with a file not found or an old version of your code.