In my project, i am using :
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
I can not remove it, because a lot of other dependencies use it.
App is working with LDAP,so ecently i have add:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.5</version>
</dependency>
Which is depends from:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
</dependency>
And now i have a lot of errors:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
Can you please help me?
Yep, I see this question
You could:
Update your version to 1.5.7 which is the latest 1.x version. It depends on slf4j-log4j12:1.5.10, so this unlikely will help.
Consider using apacheds-all:2.0.0-M15. It depends on slf4j-log4j12:1.7.5 so if this version suits you, it should resolve this problem.
UPDATE
Some other ideas:
Decouple ApacheDS from Spring
or Disable logging for the problematic packages which use the old 1.5.x bridge
or Remove this bridge (by excluding a dependency) and (optionally) add log4j configuration to see log4j logs (never tried having them both!).
Maven should be picking the latest version, but you could try adding a dependency management section, to explicitly specify which version of slf4j you want. Probably picking the most recent version out of all your various dependencies will be fine (1.7.2 in this case).
Alternatively, I've come across this issue when deploying an application into jboss, because it bundles an old version of slf4j, which takes precedence over the version in my application. You can check this by running your application (or jboss or whatever) with the -verbose:class jvm parameter, it will log out where each class is being loaded from. This would tell you if it's being loaded from the jar in your application, or something in your environment.
Related
I found two way of adding dependencies for spring boot rest service application.
Method 1 :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
Method 2:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Both method given above does the same job? Any difference in performance?
Thanks in advance
The difference between these methods is that spring-boot-starter-web contains more dependencies than just spring-boot-starter and spring-web.
For the version 1.5.8.RELEASE it will be:
spring-boot-starter
spring-boot-starter-tomcat
hibernate-validator
jackson-databind
spring-web
spring-webmvc
All other stuff depends on your requirements. For instance, if you're developing commercial product you must check all included transitive dependencies for their licenses.
The general advice is to use only features you need. Don't forget that you still can depend on top level artifact excluding not required parts using Maven feature.
At for the performance boost, basically it should not be that much. The difference is only if the Spring (with top-level artifact dependency) will load and auto configure some features which are not practically used in your code (during the classpath scanning). The startup time could be slightly increased by the same reason.
Hope it helps!
Obviously second approach is better i.e. using springboot starter pom.
Reasons I say that for are as follows:-
It allows zero configuration or auto configuration i.e. most of the web related settings would be given to you by default. e.g. by default tomcat server would be integrated, springboot dependencies would be added for you, automatic registration of converter and other web related dependencies etc. See this link.
You could take advantage of easy override i.e. if tomorrow you want to use jetty in place of tomcat just add the jetty dependency and it's configurations and now you could use jetty.
Your pom.xml would be neater and more readable as less no. of dependencies are put inside it and picked from starter poms.
Easy compatibility management. By default spring-boot picks up the version of starter parent. Hence, you could rest assured that all compatible dependencies would be downloaded as part of mvn dependencies and if you specifically want to upgrade any of those you could. But this gives advantage of upgrading to compatible dependencies by just changing the version of springboot starter parent(Note: You could use dependency management as well in place of starter parent pom. See this link).
Performance wise there would be a trade-off as springboot by default downloads more dependencies than minimum required initially. But over the time as application starts becoming mature most of these dependencies are used anyways.
In NetBeans 8, in a Maven-based project, how does one use a jar while programming but omit from build?
I need to access some specific classes in a specific JDBC driver in my Vaadin web app. But in web apps, we normally do not bundle JDBC drivers within our build (the .war file). Instead, the JDBC drivers belong in a folder controlled by the Servlet container (the runtime environment).
So, I need the JDBC driver (a jar file) to be on the classpath while I am editing my code and compiling. But that jar file must be omitted from the build.
exclusions Tag
I tried adding the exclusions and exclusion tags to my dependency element. But this did not work – The postgresql-9.4-1201.jdbc41.jar appeared in WEB-INF/lib folder.
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
<exclusions>
<exclusion>
<groupId>org.postgresql</groupId> Exclude from build
<artifactId>postgresql</artifactId>
</exclusion>
</exclusions>
</dependency>
New Profile?
This Answer by ZNK - M on the Question, Setting custom runtime classpath for a maven project in netbeans, may be what I need.
But creating a new project profile seems like overkill what seems like small little task to me. And, I always want to exclude this jar from my build output, not just when testing or in other limited scenarios.
You should add a new profile run-with-netbeans in your pom that declares the additional dependencies (use the provided scope to not include them in the release).
Then you'll have to add the new profile to your IDE to run the pom with the -P run-with-netbeans option in the command line.
But I am familiar only with the basics of editing a POM file. If that approach is the way to go, it would be helpful if someone could expand on the details and steps needed.
<scope>provided</scope>
Use <scope> tag in POM file, with a value of provided.
Excerpt from the Dependency Scope section of the page, Introduction to the Dependency Mechanism :
compileThis is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
providedThis is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
runtime[…]
test[…]
system[…]
import[…]
Like this:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
<scope>provided</scope>
</dependency>
Use the provided scope instead of the default compile scope for this dependency. That's exactly what it's for.
<dependency>
<scope>provided</scope>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
</dependency>
I am using Spring 3 and Hibernate 4 JPA. I am confused regarding javax.persistence JAR. I found below two Maven dependencies on Google. Please tell me which one is required in below two dependencies?
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
The first of those javax.persistence.persistence-api is the API Jar, which defines vendor-neutral interfaces which your application should be working with.
The second is the EclipseLink implementation of that API.
It is possible to remove references to the first javax.persistence dependency and just use the EclipseLink jar. However there is a good reason not to.
Writing and compiling your code against the vendor-neutral javax.persistence API ensures that your application code is portable to different persistence providers. For instance if you wished to switch to Hibernate, then you could put that in your pom.xml and remove the org.eclipse dependency, without changing any of your application code.
However, there's an extra little detail you should change. To ensure that your application can switch between persistence providers, the 'implementation' dependency should only be used at runtime. Otherwise, vendor-specific code could easily make its way into your codebase. Add the following to your org.eclipse dependency and see whether your application compiles.
<scope>runtime</scope>
As a result of that, you may find that your application has EclipseLink-specific code in it. This means that you could not change persistence provider without changing your codebase.
Whether that's a problem is up to you. ;)
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
Which is the lastest one and compact with hibernate 4. Also latest version of hibernate support jpa 2.1.0 please check this link
You dont need to include that dependency explicitly, it is in Hibernate pom and will be added transitively
I'm using JBoss EAP 6.0.1 (NOT JBoss AS 7.1.1 or 7.1.3!) and I'm just starting with a Maven project.
In normal Eclipse projects I set the target runtime of my project to the JBoss EAP server runtime and then all its libraries are available to my project. Available here means I can use e.g. ctrl-t to find a class in any of those libraries, and when I attach the source I can step into them when debugging.
How would I do this using Maven (m2e)?
I've found the Maven repository for JBoss EAP 6.0.1 at http://maven.repository.redhat.com/techpreview/eap6/6.0.1/
Do I need to add some root dependency (representing JBoss EAP itself) to my project, and if so, what would this dependency be?
I found a very similar question here: Adding JBoss AS 7 modules on Eclipse using Maven or JBoss Tools
But the accepted answer only says: "Take a look at these links", which doesn't tell me how to exactly do this (and it's for AS 7.1.1 not for EAP 6.0.1).
UPDATE
I wasn't entirely clear about the question. I'm not looking for a mere reference to the Java EE APIs. I know how to do that, as it's simply:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
I'm also NOT looking for any vendor versions of that spec jar. I'm absolutely NOT looking for the following one either:
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
</dependency>
What I'm looking for is having all implementation libs available in the project. The JBoss AS 6 server runtime does this by default, and with the JBoss AS 7/EAP 6 server runtime you can do this by going to Server -> Runtime Environments -> Default Classpath (you can enter individual paths there, or just add the /modules rootpath to have everything at one)
I'm looking for the equivalent of this in a Maven project.
I'M NOT LOOKING FOR SPEC JARS!!!!
As I need to step through the ACTUAL IMPLEMENTATION jars of the target server, I REALLY need the ACTUAL IMPLEMENTATION jars. I KNOW I can't deploy these, and nor do I intend to deploy them. They need to be present in my IDE, so there's source code that matches what's in the target JVM and I can use CTRL-SHIFT-T to lookup IMPLEMENTATION classes and CTRL-CLICK to navigate into them, analyse call hierarchies, etc.
AGAIN: I'M NOT LOOKING FOR SPEC JARS!!!!
You can import the dependencies manually into your repository. I did it into ours (artifactory) and it's working.
See: https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/Install_the_JBoss_Enterprise_Application_Platform_6_Maven_Repository_Locally.html
I found a surprisingly simple solution my self: even though libs are managed via Maven, and a target runtime is disabled by default, you can still explicitly select a target runtime.
The libraries this target runtime puts on the classpath will now also be put on the classpath for the Maven project, in addition to those Maven already puts there. You can (manually) attach the source code to those libraries.
Once you're doing with debugging and stepping through the internals of your AS, you can simply remove the target runtime again.
An answer that tells how to do this purely via Maven and for JBoss EAP 6.0.1 (not JBoss AS 7.1.1 or 7.1.3) would still be welcome, so I won't accept my own answer ;)
There is a nice explanation of the JBoss Maven repositories at: https://community.jboss.org/wiki/MavenRepository
I would guess the repository you need to use is: https://repository.jboss.org/nexus/content/groups/public-jboss/
it should contain all JBoss artifacts you're looking for.
Maybee the groupId/artifactId is not correct. There is a search feature for the repositories at: https://repository.jboss.org/nexus/index.html#welcome
I would recommend to not include the impl jars as you cannot deploy them anyway. So the spec jars should be ok:
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
</dependency>
see: http://www.andygibson.net/blog/quickbyte/jboss-java-ee-6-spec-dependency-in-maven/
The gav for the JBoss server seem to change a lot. JBoss 7 can be found at:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ee</artifactId>
<version>7.1.3.Final</version>
</dependency>
Take a look here:
JBoss Enterprise Application Platform Component Details
And in my pom.xml I'm using this to get dependencies from Jboss EAP 6.0.1
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<type>pom</type>
<scope>provided</scope>
<version>3.0.2.Final</version>
</dependency>
You can use Nexus or Git or Overlord to manage project artifacts in order to create a proxy virtual dependency, if i am not mistaken.
Runtime artifacts can be used:
<!-- https://mvnrepository.com/artifact/org.jboss.bom/eap-runtime-artifacts -->
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>eap-runtime-artifacts</artifactId>
<version>7.1.0.GA</version>
<type>pom</type>
<scope>import</scope>
</dependency>
See https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.1/html/development_guide/using_maven_with_eap#manage_project_dependencies
I haven't yet found an answer to this question which is bugging me for long. I am trying to integrate Hibernate (3.6.7) with Spring (1.2.8). In order to do so i have to get a bunch of jars just to get it running. Isn't there a more cleaner of way of getting this done. The jars i am using rather forced to use are as below:
spring-1.2.8.jar
commons-logging-1.0.4.jar
hibernate-3.6.7.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
dom4j-1.6.1.jar
slf4j-api-1.6.1.jar
javassist-3.12.0.GA.jar
Is there no leaner way? The big list of dependent jars could potentially cause conflict during deployment to my appserver in the future. So its making me rethink about spring-hibernate integration. Is there a way to reduce this dependency list. My issue is not related to management of jars as maven is already being used, it more to do with the usage.
This answer was posted before the OP mentioned that he was using Maven. The question seems to be asking how he can use code without including it in his project. Given that there is no answer to that question I'll answer assuming he wants a better way of managing the dependencies that he needs.
The leaner way to do this is to use a dependency management tool such as maven. This allows you to define your project's dependencies in an xml file.
The dependencies you specify will also have dependencies and so on. These are transient dependencies and are very hard to manage without an automated tool.
This is also the best way to ensure that you only have the jars you require.
The dependencies you require are:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
and:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>