How to compile a file in Maven project - java

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).

Related

3rd party jar which can not be put in any repository works with maven project

There is a 3rd party jar which is dependent by many programs on the target machine. That jar file is named as abc.jar.
I can add the jar file to the local repository as abc-1.0.jar and package my project. But that means I must manually replace abc-1.0.jar when abc.jar updates. Here are my questions:
1.Is it possible to just use abc.jar when development with Intellij IDEA? I tried add the abc.jar to the External Libraries with dependency adding. But the editor can not recognize classes within abc.jar
2.If the answer is yes, What should I do to let the war file use the system level's abc.jar not the bundled within the ear?
Many thanks
Find this?
correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project
or compile files in Gradle
compile files("src/main/resources/libs/sqljdbc4.jar")
put jar file to path
You can add the abc.jar file to the particular module's dependency manually as described in mentioned SO answer and you also will have to manually add it to the artifact which is automatically generated by IDE based on Maven configuration.
Note that the artifact configuration will be overridden on the next re-import from Maven unless you create a copy of this artifact configuration and give it another name.
Generally such approach is not recommended for Maven project. Instead you should relay on Maven configuration.

Add library into jar of project

My problem is with a project where I use the POI library. It's from apache and allows you to work with excel,word, ... .
I had to add some jar files to my library and it runs perfect.
The problem is when I put my JAR file somewhere else.
It gives me the errors it can't find the librarys.
Is there a way I can put my librarys into the 1 jar?
I already tried to add my lib folder as source package but that didn't help.
there is a Maven plugin for Eclipse called M2Eclipse, which will read a POM and construct a classpath out of jars it finds in the local repository and any remote repositories you've configured. It behaves largely like Maven does in terms of finding the latest version for a given jar (if you've specified a version range in your POM).
You can also have a look on this
http://fredpuls.com/site/softwaredevelopment/java/deploy/five_strategies_for_managing_j.htm
You want to make a 'shaded' or 'uber' jar, which has all of its dependencies included
There is a maven plugin for building a shaded jar.
https://maven.apache.org/plugins/maven-shade-plugin/
For me the fastest/ easiest solution was to just open my project in eclips and export is a runable JAR then it adds the librarys to the JAR.
NetBeans builds your application into the project's dist folder. There is also a readme file in it, that tells you, you should distribute the contents of that folder...
Edit
Remove the lib folder, that is shown on the second image, from your sources.

Issue creating Jar files (repository is from github)

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.

Setting up a maven project for already made jars

I have some jar files that I need to include in my build - I'd rather not specify them as system dependencies - that creates a nightmare for setup. I have been uploading them to artifactory and then they can be pulled down directly, but I won't always have access to artifactory while building.
What I was thinking of doing is creating a project that has these jar files in them. It could be one per or all of them (open to suggestion). I was wondering if there is a graceful way to handle this?
What I have done (which is clearly a hack) have a project that takes the jar and during the compile phase it unpacks the jar into the target/classes directory. It then packs those class files back during the package phase. it essentially creates the same jar file again...massively hackey. Could I add the jar into the resource area or is there a different project type I could use? I am open to any ideas.
You may try to use install:install-file. I would go about it in the following way.
Create project that contains all your jars in some location
Configure install:install-file in pom of this project to install jars in repository in some early phase.
Make sure that this pom is executed before anything else that depend on it. List it as first module.

How to build project from maven pom file

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there.
So given a pom file how do I build the project from it?
mvn install should get you going
I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...
It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.
Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.
FOLLOW UP
Thanks for advice. I was not able to use the command mvn install as it gave errors.
Probably because you hadn't checked out the source.
I don't know how to check the source tree of the project ...
Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.
If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.
... as I thought POM itself should have this information to automatically checkout if the source is not check out.
It doesn't necessarily, though in this particular case it does.
Anyway I was able use Eclipse to build the project without errors.
(Other readers can read #icyrock.com's answer for links to the m2eclipse plugin and documentation.)
The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.
But I would like these dependent jars to be relative to dir where POM file is.
Sorry, but that is not the way Maven works.
The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)
If you want to open this within Eclipse, you need to install m2eclipse:
http://www.eclipse.org/m2e/
and then import the project as a Maven project as described here:
http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Try out their getting started guide. It has a lot of good examples:
http://maven.apache.org/guides/getting-started/

Categories

Resources