Maven dependency compile error : package does not exist - java

Maven dependency compile error : package does not exist
I have maven parent project which has dependency with another child project's jar file.
Child's jar file is build and success. When building parent again, I got "package does not exist" error.
When I extract the jar file using 7-zip which is present in 'target' location, those packages and its files does exist. I extracted the jar file using 'jar command'as well, files are present. But, when I open the same jar file using Beyond compare 3, those packages are missing.
Somehow maven and Beyond compare unable to identify the packages or is it different problems with maven and beyond compare? I am not sure. After breaking head for two days, no clue about it.
I am using Eclipse Kepler IDE and there are no compilation errors in the project.
Below is the maven version
Below is the artifact code
<groupId>net.pi.run.cut</groupId>
<artifactId>run.cut.receive.mba</artifactId>
<version>7.8.3</version>
<packaging>jar</packaging>
and the dependency code
<dependency>
<groupId>net.pi.run.cut</groupId>
<artifactId>run.cut.receive.mba</artifactId>
<version>7.8.3</version>
</dependency>
Old 7.8.1 version is working fine. Jar has all content.
Below is the img from beyond compare tool, where it doesn't identify the package and its files. P.S. I m necessarily scrapping the folder names with purpose.
Below is the image sample from 7-zip
All your suggestions are welcome.

Related

Maven: How to add all jar files in lib folder during a web application build

I have an old project. I am trying to add maven build to the project.
All the jar files in the project are present currently in the WEB-INF/lib folder.
Is there a way to add these jar files to the classpath during source compilation and then have it in the war file lib
This is one of the places where switching to Maven hurts. There are a lot of suggestions where most short-circuit something you will need later, and hurt you there. I would suggest that you
Move your jar files out of the lib folder into another project folder not meaning anything special to Maven.
For all jars that you easily recognize, make the proper Maven dependency in your pom file. This will allow Maven to download sources and javadoc if present.
For the remaining jars, you can tell Maven to install them as part of your normal build as custom dependencies. I asked the same question years back and got a very useful response at Multiple install:install-file in a single pom.xml. This will allow you to get up and running quickly.
When you have the time, locate proper replacements for your custom dependencies.
Take your time doing this. It is tedious work but it pays off quickly.

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.

How to compile a file in Maven project

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

How to include jars that load other jars in maven?

I am developing a Java application in NetBeans and using maven for the dependencies. I have a bunch of jars located in a folder. These jars load other jars located in a path known to them. It seems to me that, when i load a local jar in maven, it is actually copying the jar to another location. The problem is that the moved jar can't find the other jars anymore because now the relative path to them jars is broken.
Is it possible to use maven in such way that the included jars are not moved from their original place so they can find other jars? Or if this is not possible, is there a way to give maven an entire folder that contains subfolders, and if maven moves the entire folder, it would also move all the subfolders with the jars inside them?
I am not sure if I was clear enough. I am also new to maven. It seems to me that ant is more flexible in this regard.
Edit: After reading the comments it seems I was not very clear. Basically the company I work for has two applications that share some common jars that load other jars with URLClassLoader. I don't want to distribute these common jars again, i want my second application to find and load those jars from the location where my first application has put them. I found a solution by using maven to import one jar that uses URLClassLoader with a hard-coded path to load the other jars.
I have a module which pom file contains these lines in the beginning:
<groupId>com.domain.project</groupId>
<artifactId>MyFirstProgect</artifactId>
<packaging>jar</packaging>
<version>1.2.3-snapshot</version>
After I compile this project maven will put it into the local repository (mine is situated in the C:\Users\MyUser.m2\repository, in linux it should be somewhere in /home/myUser/.m2/repository).
Afterwards I can add a dependency in the second project like this:
<dependency>
<groupId>com.domain.project</groupId>
<artifactId>MyFirstProgect</artifactId>
<version>1.2.3-snapshot</version>
</dependency>
In my case this helped me.
P.S. But this will lead the whole first project to be added as a dependency. So maybe this is not the perfect solution for you.

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