Problems with maven apache mina pom.xml - maven

I have following entries in my pom.xml.
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-filter-compression</artifactId>
<version>2.0.7</version>
</dependency>
I am getting "Missing artifact org.apache.mina:mina-core:bundle:
2.0.7" error in my pom.xml .
Could someone please help in resolving this error.

Add to your pom file:
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>

Addition to the accepted answer, an explanation why this is necessary:
The various MINA dependencies rely on OSGi bundle artifacts rather than standard JAR files.
As such, it's necessary to add support for these bundle to Maven using the Apache Felix maven-bundle-plugin.
See https://stackoverflow.com/a/5409602 for a good explanation of OSGi bundles, with links to more info.

Related

Not able to connect Google Cloud Datastore with AEM 6.5 : Bundle has resolved dependencies

I have a requirement to connect google cloud datastore from AEM. I have added the dependencies in main pom and core pom.
MAIN POM
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>16.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>de here
Core POM
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
</dependency>
When I deploy my bundle is in insatlled state and has the following errors
com.google.auth -- Cannot be resolved
com.google.auth.oauth2 -- Cannot be resolved
com.google.cloud -- Cannot be resolved
com.google.cloud.datastore -- Cannot be resolved
try adding those libs to the embed-dependencies in the POM. Also check that your libs are inside the .jar file generated.
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- <Embed-Dependency> artifactId1, artifactId2;inline=true </Embed-Dependency> -->
<Export-Package>we.retail.core.model*</Export-Package>
<Private-Package>we.retail.core*</Private-Package>
<Sling-Model-Packages>
we.retail.core.model
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
In the embed you can try something like: google-cloud-datastore
Also take care with the import type that you're using.
Link to Maven
Hope you can find the answer
If you do not need those, exclude them from the <Import-Packages>:
<Import-Package>
!com.google.auth.*,
*
</Import-Package>

Add external library .jar to Spring boot .jar internal /lib

I have an external .jar that cannot be imported from public repositories using pom.xml, it's sqljdbc41.jar.
I can run the project locally from my IDE, and everything will work. I referenced the library after downloading it like so:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sqljdbc41.jar</systemPath>
</dependency>
When I run mvn clean package to create my .jar file and try to run the created .jar, a mistake will pop up, which mentions the SQL Server references are not valid. I then extracted my .jar file and true enough, everything that is referenced in the pom.xml file properly gets downloaded and added, however, my SQL Server does not.
I can, in a very hacky way* just manually add the sqljdbc41.jar to my /lib folder after it's been compiled as a .jar, and it'll work, however that seems highly unoptimal. What would be a better approach?
*Opening the .jar file with Winrar, going to the /lib folder, manually selecting my sqljdbc41.jar file, then make sure to select the No Compression option bottom left where Winrar gives you compression options, in case you find this by Google and no one answered.
you can set 'includeSystemScope' to true.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
You could install the sqljdbc41.jar in your local repository :
mvn install:install-file -Dfile=path/to/sqljdbc41.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc41 -Dversion=4.1 -Dpackaging=jar
And then declare the dependency as a standard dependency :
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
</dependency>
If you use a remote artifact repository (nexus, archiva...) you also need to deploy the artifact on this repository. You can find more here : https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
Another way, you can put it into the resources folder, such as resources/lib/xxx.jar, then config the pom.xml like this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/sqljdbc41.jar</systemPath>
</dependency>
In Spring Boot: I also faced similar issue and below code helped me.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
It works for me:
project {root folder}/libs/ojdbc-11.2.0.3.jar
pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.3</version>
<scope>system</scope>
<systemPath>${basedir}/libs/ojdbc-11.2.0.3.jar</systemPath>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
In my case, the fault was providing a version number without "dot" in tag:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
This one works:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.8</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
When Spring-Boot projects are used with maven or gradle plugins they packaged the applicaiton by default as executable jars.
These executable jars cannot be used as dependency in any another Spring-Boot project because the executable jar add classes in BOOT-INF/classes folder. This means that they cannot be found when the executable jar is used as a dependency because the dependency jar will also have the same class path structure as shown below.
If we want to use project-A as a maven dependency in project-B then we must have two artifacts. To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as a dependency.
To configure a classifier of exec in Maven, you can use the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
So the MAJIC WORD here is <classifier>exec</classifier> this will create a jar structure as below and then it could easily be conusmed by spring-boot project as maven dependency jar on class path.
The above plugin need to be add in project-A pom that is going to be used as dependency in project-B. Same is explained in spring documentation section 16.5. as well.
In order to work through the local repository, the target .jar file that we will work with must be in the s2 folder. Several methods can be used for this:
The file can be taken manually and put in the relevant place (not
preferred). The same process can be done by installing it via the
console.
Relevant Remote URL is written in the .pom file dependencies and
automatically places it in the s2 folder when Intellij is refreshed
(validate) in the IDE used.
The same process can be done by addressing the .pom file dependencies via the centeral repository.
Attention: ComponentScan should not be forgotten for the related jar work on SpringBot.

maven ignoring findbugs suppressFBWarnings annotation

I have 2 projects that I am using the FindBugs plugin in maven to identify bugs. I am also using the #SuppressFBWarnings annotation to ignore specific bugs.
With the first project, I added the dependancies to the pom.xml and both the findbugs report and the annotation worked fine. With the second project, the report gets generated, but it still identifies bugs that I have suppressed using the annotation.
I run mvn clean install site to generate the reports on my machine in the build folder.
Each of the 2 projects I mentioned, have sub-projects with their own pom.xml files in their sub-directories, so in the parent directory, I also have a pom.xml. This directory layout is mirrored identically in both of the main projects.
Here is the XML I added to the parent poms under the <reporting> tag:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<fork>true</fork>
<threshold>Low</threshold>
<effort>Min</effort>
</configuration>
</plugin>
Also, in this same parent pom, I added this to the <dependencyManagement><dependencies> section:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
This is identical in both of the main projects poms.
Now, in the sub-projects where I actually use the #SuppressFBWarnings annotation, and only in that particular sub-project, I have this under <dependencies>:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
Also, this is mirrored in the other working project. I copied and pasted directly.
One project works perfect and I can successfully suppress false positives. The other project completely ignores the #SuppressFBWarnings anotation, and I can't seem to fix it.
Is there something I'm missing here?
I think that if an annotation is not found, instead of giving an error, it will just ignore it? How can I tell if its not found?
Hopefully this is a simple fix.
Thanks.
#SuppressFBWarnings was introduced with the annotation in version 3. That's why it should look like this:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>
Try to add annotations artifcat to the plugin dependencies :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<fork>true</fork>
<threshold>Low</threshold>
<effort>Min</effort>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</plugin>
Ensure that the dependency added is in between the dependencies tags.
Like this:
<dependencies>
<dependency>
<groupId>something</groupId>
<artifactId>something</artifactId>
<version>something</version>
</dependency>
<dependencies>

latest version of a dependency in maven archetype [duplicate]

Are there any preexisting Maven plugins or commands to update the dependencies in the POM?
Example: (if this was in my POM)
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
Is there a command or plugin I can run to get it to update the dependency to:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
Try the maven-versions-plugin, in particular, the versions:use-latest-versions goal.
I prefer using mvn versions:display-dependency-updates; this generates a report of which dependencies can be upgraded, but lets you modify the POMs yourself. There's also a display-plugin-updates command for plugins.
you can use dependencyManagement in your parent pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
this way, you need to change the version only once in the parent POM
Personally, I think there should be an additional parameter in maven that would allow you to add to the pom.xml.
See post at http://maven.40175.n5.nabble.com/Is-there-any-maven-plugin-to-add-dependency-to-existing-pom-xml-td2839092.html#a5772853
Here, you can add the following to your pom.xml file:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
...
</plugins>
...
</build>
...
</project>
...
Then backup your pom.xml file via version set command:
mvn versions:set -DnewVersion=9.9.9
Run latest versions:
mvn versions:use-latest-versions
and diff the pom.xml files, pom.xml and pom.xml.versionsBackup
No there is isn't. And be happy there is not. How would such a tool know how to upgrade your dependencies?
With breakages possibly happening between minor versions, it would be a disaster waiting to happen.
But you can always write your own Mojo for that.
get latest version of dependency from Maven repository
compare with version from pom.xml
rewrite pom.xml
run mvn test
?
Profit!
I had the same kind of problem and finally solved it by writing a bash script.
GitHub repository - Update POM Shell
This is a shell script that allows you to update a dependency on different modules directly from the command line.
It is particularly useful when you need to update one or more dependencies on different modules at once.

Why can't maven find an osgi bundle dependency?

I have declared a OSGi bundle as a dependency in my maven project. ( It just happens to be the felix container. )
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>4.0.2</version>
<type>bundle</type>
<scope>compile</scope>
</dependency>
When I try to build, it says it can't find it.
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) org.apache.felix:org.apache.felix.framework:bundle:4.0.2
Try downloading the file manually from the project website.
But, a quick look in central verifies that this artifact is indeed there. I noticed that if I change it to a "jar" type, it will indeed download the jar ( bundle ) for me. Which got me to thinking, why did I call it a bundle in the first place? Well, I did that because when I was using m2e to lookup the artifact, it called it a "bundle"; in fact, m2e generated those coordinates that I cite above.
Is bundle not a valid maven artifact type? If not, why does m2e call it that?
This is not a glitch in m2e as mentioned in the accepted answer. The problem is that maven doesn't know what the type "bundle" is. So you need to add a plugin that defines it, namely the maven-bundle-plugin. Notice that you also need to set the extensions property to true. So the POM should have something like
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
</plugin>
The problem with the accepted answer is that it works if the dependency of type bundle is a direct dependency; since it is your pom that declares it, you can just remove the type. However, if your dependency itself has a dependency of type bundle then you are screwed because then one of your transitive dependencies is of type bundle and you cannot just remove the type in it since you are not the owner of that artifact and don't have access to the pom, which again your current execution doesn't understand. it will try to look for repo/your-dependency.bundle
I ran into this problem when using the dependency plugin to copy-dependencies. In that case, the plugin dependency has to go in the plugin itself. You just need the dependency plugin to know about the bundle plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<extensions>true</extensions>
</plugin>

Resources