how to add my one project jar in another maven project in netbeans - spring

I have one project jar oauth.
I want to add it in another maven project . I tried to change pom.xml file but no effect. Can anyone please suggest me?
I tried to add following dependency in my pom.xml file:
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapps/WEB-INF/lib/auth.jar</systemPath>
</dependency>

With the assumption that you have that auth.jar in your local repository (as it builds fine).
Why don't you give a try like this.
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Honestly speaking I don't prefer to give the jar location in my pom file and using scope as system, I leave this task to handle by Maven to resolve all the artifacts either by searching in local maven repository first(/.m2) or in MAVEN CENTRAL REPO if it is a 3rd party jar.

Related

Missing jar in maven repo

Library depends on library, which missing in maven central (error 404 missing library). I tired to download the same library from an external source and placed into local Maven Repository, but it's not working. How can I solve this problem?
The following artifacts could not be resolved: javax.media:jai-core:jar:1.1.3, com.sun.media:jai-codec
:jar:1.1.3: Failure to find javax.media:jai-core:jar:1.1.3 in http://repo.maven.
apache.org/maven2 was cached in the local repository, resolution will not be rea
ttempted until the update interval of central has elapsed or updates are forced
If I adds these libraries in pom of my project(just for testing local repo), it's ok (from local repo). Problem, that another library depends on them.
My pom.xml:
<dependency>
<groupId>de.intarsys.opensource</groupId> //lib in maven central
<artifactId>jPodRenderer</artifactId> //depends on libs below
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>javax.media</groupId> //in local repo
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
Can you just try it out.
I'm not sure I understood your question.
Pom.xml
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>de.intarsys.opensource</groupId>
<artifactId>iscwt</artifactId>
<version>5.5</version>
</dependency>
Make sure that the version of jar file you download has the same version with the file in pom.xml.
Make sure that you put the jar file in the correct directory.
The fastest solution is to add a Maven repository in your project source code. See here for an example on how to add a library to a custom maven repository :
http://david-codes.blogspot.com/2014/03/maven-add-custom-repository-in-your.html
There's a difference in the name:
maven was searching for jar-core, but you refer to jai_core
The first one is available on https://repository.jboss.org/maven2, the second one on maven central https://repo1.maven.org/maven2

How to add Maven dependency jar file from the lib folder

I am trying to add a jar file to the Maven dependency in my project. The settings.xml is configured to set the repository to a public repository. But this particular jar is not present in that repo. As i have the jar in my lib folder, how can i configure the Maven dependency to take this jar?
Have a look at system dependencies.
You basically need to define <scope>system</scope>.
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>
This is if you don't have your own hosted artifact repository server such as Nexus, Artifactory or Archiva.
If you do, then as Karl-Heinz suggested, you would be better off placing it there, as it's not good practice to commit binary artifacts to version control.
Another option is to set up a repository that is backed by a directory inside your project, per this answer: https://stackoverflow.com/a/2230464/433789
Changing pom.xml worked for me (jar in "/lib" directory in the root project folder) :
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/gson-2.8.6.jar</systemPath>
</dependency>
The best solution is to start using a repository manager like Nexus and put it there. Or you can use the non-maven-jar-plugin.

Nexus sonatype does not get zip dependency

I have setup Sonatype Nexus with Maven and seems to be working. However, my project depends (transitively) on docbook-xsl-1.75.2 but instead of a jar there you find a zip file. Is this the reason why Nexus is not getting it, that it is a zip file? I haven't found any Nexus configuration page in the web console offering a possible filter.
I browse my Nexus repository and see it gets the pom file but nothing else.
That module has no main artifact, it's packaging type is set to "pom".
What it does have is two additional artifacts which can be retrieved using Maven module classifiers as follows:
<dependency>
<groupId>net.sf.docbook</groupId>
<artifactId>docbook-xsl</artifactId>
<version>1.75.2</version>
<classifier>resources</classifier>
<type>zip</type>
</dependency>
And
<dependency>
<groupId>net.sf.docbook</groupId>
<artifactId>docbook-xsl</artifactId>
<version>1.75.2</version>
<classifier>ns-resources</classifier>
<type>zip</type>
</dependency>
Sorry, I have no idea how you'd retrieve these as transitive dependencies.
The next day, and after restarting Nexus it pulled the dependency. I don't still understand the magic behind Nexus not seeing the dependencies while they are clearly available but at least this question is resolved.

Maven - Sharing libraries between projects

I'm working on a multi-project, and right now I have a structure that resembles this (actually there are a couple of jar projects and a couple of war projects)
/myProj
|_______projA (jar)
| |____pom.xml
| |____target/jar files
|_______projB (war)
| |___pom.xml
| |___web-inf/lib/jarfiles
|_______projEar
| |___pom.xml
|___pom.xml
What I want to achieve, is to make projA and projB to read their dependences from a common shared folder, instead of keeping their own copy.
Actually, I don't really care where they read them from at compile time, but when I package my EAR file, I want each jar/war to appear just once, hence reducing the EAR size.
I've tried declaring the dependencies on the parent pom, declaring the dependencies as and some other things, but so far I haven't achieved this.
Is there an easy way to achieve this? Any simple maven plugin?
Thanks in advance.
You should be able to do this by adding the JAR as a dependency to your EAR's pom.xml:
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
...and specifying the dependency as provided in your WARs' pom.xml:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
If Maven/other tooling has already copied the JAR to your WEB-INF/lib directory, you may need to delete the file manually prior to rebuilding.
This should result in an EAR of the form:
META-INF/MANIFEST.MF
lib/myapp-utils-0.0.1-SNAPSHOT.jar
META-INF/application.xml
myapp-web.war
When you are moving to Maven, you should not store the dependency JAR's in your code base. I would suggest you to create a central Maven repository which will contain all the dependencies.
Refer mvn install to first install these artifacts into the local repository. Also, you can refer to the maven central repository to get artifacts while building.
What you need to do is: remove all the dependency jar's from the source code, and all their dependency in the pom.xml. These would be downloaded and packaged from the maven central repository as and when required. Set the Dependency Scope of the artifacts accordingly.

How to generate Javadoc for Maven Dependencies

I have a maven project with the following POM snippet:
<modelVersion>4.0.0</modelVersion>
<artifactId>Foo-Deploy</artifactId>
<name>Foo-Deploy</name>
<packaging>pom</packaging>
<description>foobar</description>
<dependencies>
<dependency>
<groupId>de.foo.bar</groupId>
<artifactId>some-api</artifactId>
<version>${project.version}</version>
<classifier>doc</classifier>
<type>zip</type>
</dependency>
</dependencies>
The idea is to have a dependency defined in which some sources are (this is created successfully before).
Now I want to run javadoc on exactly THIS dependency. When I call
mvn javadoc:jar -DincludeDependencySources=true -DdependencySourceIncludes=de.foo.bar:some-api:*:doc:zip
it fails with the message
Not executing Javadoc as the project
is not a Java classpath-capable
package
what is wrong ? and would it work anyhow ?
or how can I generate javadoc from a specific dependency (assuming this project has more dependencies) ?
Thanks
To generate javadoc for dependent sources, a sequence of steps needs to be done. These are outlined in this link.
Essentially you need to ensure that the source files of the dependency is generated/available and <includeDependencySources> parameter is enabled.

Resources