SLF4J multiple binding shaded - jar

I have a shaded executable .jar that contains an embedded Jetty server. I only have one version of SLF4J (1.6.1) as a dependency, however, when the .jar is shaded using the maven shade plugin, SLF4J sees this as having multiple bindings since the dependency is packaged on both the classpath as well as at the root of the .jar
org
|_ slf4j
|_ ...
WEB-INF
|_ lib
|_ slf4j-api-1.6.1.jar
|_ slf4j-log4j12-1.6.1.jar
`SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/episner/Desktop/rmt/webapp/WEB-INF/l
ib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/episner/Desktop/rmt-2.2.2-SNAPSHOT.w
ar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.`
Is there any way to either supress this message or modify my maven build to remove the duplication?

Modify your POM so that your dependencies do not pull SLF4J at all.
Hopefully they will all be happy with the SLF4J version already available on your classpath.
Something along the lines of
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

Related

Maven Dependencies Jar Missing for Slf4j wrapper

I have a project in Maven for ExtentReports. When I run it, the test fail and says.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
When I check the project properties -> java build path -> libraries. ->Maven Dependencies
rxjava-3.0.4.jar (missing)
freemarker-2.3.30.jar (missing)
lombok-1.18.12.jar (missing)
when I go to POM.xml
4.0.0
it says:
could not transfer artifact io.reactivex.rxjava3:rxjava:jar3.0.4
I tried downloading the said jars in mvn repository but it doesnt make any changes.
SLF4j wrapper is generally provided by Lombok.
I recommend you put these dependencies in your pom.xml:
You need the SLF4j wrapper AS WELL AS a dependency for which implementation you want to use. (Logback in this case).
<!--region Lombok Configuration -->
<!-- logger guide https://gist.github.com/stykalin/8c77ad2a705eabddc2424eff0e99d1ec -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
<!-- endregion -->
Also, you will need to setup a src/main/resources/logback.xml file. Also, put #Slf4j Lombok annotation at the top of your class files where you need to do a log.info("Message").
IF you still have problems, the command mvn dependency:tree can perhaps help you find dependency conflicts.

Alfresco Configuration to Eclipse or by Maven

I am trying to configure the development environment for Alfresco version 5.0.b.
i have tried as per the documentation for maven and also tried by my way in eclipse but i am facing an issue with both like
if i do it by maven from command prompt like
C:\maven_projects\project_1>mvn install
[INFO] Scanning for
projects... Downloading:
https ://repo.maven.apache.org/maven2/org/alfresco/maven/alfresco-sd
k-parent/2.0.0-beta-4/alfresco-sdk-parent-2.0.0-beta-4.pom [ERROR] The
build could not read 1 project -> [Help 1] [ERROR] [ERROR] The
project ipr.res.in:project_1:1.0-SNAPSHOT (C:\maven_projects\proje
ct_1\pom.xml) has 1 error [ERROR] Non-resolvable parent POM: Could
not transfer artifact org.alfresco.
maven:alfresco-sdk-parent:pom:2.0.0-beta-4 from/to central
(https: //repo.maven.a pache.org/maven2): repo.maven.apache.org and
'parent.relativePath' points at wro ng local POM # line 12, column 13:
Unknown host repo.maven.apache.org -> [Help 2 ] [ERROR] [ERROR] To see
the full stack trace of the errors, re-run Maven with the -e swit ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] [ERROR] For more information about the errors and possible
solutions, please rea d the following articles: [ERROR] [Help 1]
http: //cwiki.apache.org/confluence/display/MAVEN/ProjectBuildin
gException [ERROR] [Help 2]
http: //cwiki.apache.org /confluence/display/MAVEN/UnresolvableMo
delException C:\maven_projects\project_1>
If i try in eclipse
i create one project as maven project in that i add the catalog file with maven central for the url (http: //repo1.maven.org/maven2/archetype-catalog.xml) but when i try to import the archetype (org.alfresco. ..) it is not giving me anything.
So kindly help me out for the issue to configure the AMP
My Project POM.XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http: //maven.apache.org/POM/4.0.0" xmlns:xsi="http: //www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http: //maven.apache.org/POM/4.0.0 http: //maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alfresco.tutorials</groupId>
<artifactId>quick-start-project</artifactId>
<version>1.0-SNAPSHOT</version>
<name>quick-start-project Repository AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the quick-start-project Repository AMP (Alfresco Module Package)</description>
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-parent</artifactId>
<version>2.0.0-beta-4</version>
</parent>
<!--
| SDK properties have sensible defaults in the SDK parent,
| but you can override the properties below to use another version.
| For more available properties see the alfresco-sdk-parent POM.
-->
<properties>
<!--
| Defines the groupId for the Alfresco Artifacts to work against. As of 4.2 the only allowed value is: org.alfresco
| NOTE: See http: //docs.alfresco.com/4.2/concepts/dev-extensions-maven-sdk-tutorials-alfresco-enterprise.html for details
-->
<alfresco.groupId>org.alfresco</alfresco.groupId>
<!-- Defines the Alfresco version to work against.
Community versions are typically identified by major.minor.character (4.2.a) while Enterprise versions are identified by major.minor.digit (4.2.0) -->
<alfresco.version>5.0.a</alfresco.version>
<app.log.root.level>WARN</app.log.root.level>
<alfresco.data.location>alf_data_dev</alfresco.data.location>
<!-- Defines the target WAR artifactId to run this amp, only used with the -Pamp-to-war switch
. | Allowed values: alfresco | share. Defaults to a repository AMP, but could point to your foundation WAR -->
<alfresco.client.war>alfresco</alfresco.client.war>
<!-- Defines the target WAR groupId to run this amp, only used with the -Pamp-to-war switch
. | Could be org.alfresco or your corporate groupId -->
<alfresco.client.war.groupId>org.alfresco</alfresco.client.war.groupId>
<!-- Defines the target WAR version to run this amp, only used with the -Pamp-to-war switch -->
<alfresco.client.war.version>5.0.a</alfresco.client.war.version>
<!-- This controls which properties will be picked in src/test/properties for embedded run -->
<env>local</env>
</properties>
<!-- Here we realize the connection with the Alfresco selected platform
(e.g.version and edition) -->
<dependencyManagement>
<dependencies>
<!-- This will import the dependencyManagement for all artifacts in the selected Alfresco version/edition
(see http: //maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies)
NOTE: You still need to define dependencies in your POM, but you can omit version as it's enforced by this dependencyManagement. NOTE: It defaults
to the latest version this SDK pom has been tested with, but alfresco version can/should be overridden in your project's pom -->
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-platform-distribution</artifactId>
<version>${alfresco.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Following dependencies are needed for compiling Java code in src/main/java;
<scope>provided</scope> is inherited for each of the following;
for more info, please refer to alfresco-platform-distribution POM -->
<dependencies>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-repository</artifactId>
</dependency>
</dependencies>
</project>
As the Maven error message explains, the Alfresco Maven SDK is not available in Maven central. It is only available from the Alfresco Artifacts Maven repository
You therefore need to add this snippet into your pom:
<repositories>
<repository>
<id>alfresco-public</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</repository>
</repositories>
You can find out more from the Alfresco Maven SDK wiki page and the Alfresco Artifacts Maven Repository wiki page

m2e-webby and provided dependencies with jetty

I have a maven project with some provided dependencies and I am trying to run the application with webby but it give me a java.lang.ClassNotFoundException exception.
In this link it says: "Webby allows to initialize a launch configuration from the configuration of the jetty-maven-plugin".
My question is it is possible to also pass the dependencies defined in the jetty-maven-plugin? If not how can webby resolve the provided dependencies?
Want I did was to create a profile in the pom project:
<profile>
<id>webby</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>version</version>
</dependency>
</dependencies>
</profile>
And then right click on the project -> properties -> Maven and added webby to the Active Maven Profiles

HttpServletRequest getPart(") not found

I don't know why it is not working.
I am trying to accept multipart-formdata in my servlet but request.getPart("") is not showing. I am using glassfish 3.1.2 server. Tha framework used is vaadin for developing application. Can any one help me to fix this problem?
Assuming that your concrete problem is indeed that your IDE didn't show the getPart() method on autocomplete, then that can only mean that the project is not configured as a Servlet 3.0 compatible project. That method was namely introduced in Servlet 3.0.
You didn't tell anything about which IDE exactly you're using and your question history doesn't give any clues as well, so let's assume that it's Eclipse which is rather widely used. In that case, you need to configure it at 2 places, provided that you've correctly associated the Dynamic Web Project with a Servlet 3.0 compatible container as Targeted Runtimes in project's properties (otherwise HttpServletRequest and consorts wouldn't have compiled at all):
In the Project Facets section of project's properties, the Dynamic Web Module version must be set to 3.0.
If your IDE has generated a /WEB-INF/web.xml file, then you need to make sure that its <web-app> root declaration also matches Servlet 3.0, otherwise it would still fail during runtime.
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
I had the same problem. Here's what eventually turned out to be the problem for me. I had a dependency on:
<dependency>
<groupId>com.googlecode.jsontoken</groupId>
<artifactId>jsontoken</artifactId>
<version>1.1</version>
</dependency>
And it turned out jsontoken has a dependency on servlet-api 2.5. So what fixed the problem was simply this:
<dependency>
<groupId>com.googlecode.jsontoken</groupId>
<artifactId>jsontoken</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
This worked for me
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
To those that stumble on this later, if the resolution suggested by BalusC does not resolve the problem for you please check your build path for provided libraries whose runtime does not match the runtime of your server.
For example if your maven pom.xml contains entries that provide java EE libraries like so...
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>5.0-1</version>
<scope>provided</scope>
</dependency>
... they can interfere with what your IDE perceives as the runtime environment, which will be used to provide code completion suggestions.
The easiest way to track the problem is to figure out where the HttpServletRequest class is sourced from.
maven.. pom.xml.. modify this dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
servlet api 2.5 is not work
I had the same problem, I want to share it with you in case anyone else bumps in the same problem:
In my case I had a j2ee.jar which was automatically downloaded and its version was probably old. It was located under Libraries --> j2ee Runtime Library (stackoverflow doesn't let me add an image so in eclipse - in Project Explorer - expand the project --> Java Resources --> libraries --> J2ee Runtime Library --> j2ee.jar)
I went to the file system where this file was located (you have the location next to the file in eclipse) and replaced it with a newer jar. You can take the jar from here.
Then clean and rebuild the project.
One possible reason, as pointed out in Bjørn's answer, is a conflicting artifact servlet-api (Servlet 2.5 spec).
In my case it was this dependency
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.30.10</version>
To find out which dependency compiles the conflicting library just build and print the dependency tree with:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true
Part of the output:
Finally exclude the artifact from the dependency
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.30.10</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Hi friends I too faced simillar problem and I will tell you what I did.
I'm using eclipse juno and Tomcat 7 server. Make sure you use latest servlet API jar. Tomcat 7 will only support dynamic module version 2.5 not more than that. So use higher Tomcat version or lower dynamic module version then it will work.
One more thing: open your servlet api jar and see whether it contains "Part" you can easily check it.

Can you use a SWF as a dependency for a Flex Mojos Maven build

I have a maven project with flex-mojos 3.1.0. Can I have a module with swf packaging and configure a dependency on it in another module? When I do, I get a compilation error.
project
| - module1:swf
| - module2:swf
module2/pom.xml:
<parent>
<groupId>com.mygroup</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>swf</type>
</dependency>
</dependencies>
Seems to be impossible
If you need module-to-module dependency to ensure correct build order for your modules then you can simply create a parent pom for both modules and arange build order in it.

Resources