Maven - how to put the build dependance jar files? - maven-2

I run a simple CXF maven project http://cxf.apache.org/docs/using-cxf-with-maven.html, and get error below
[INFO] [cxf-codegen:wsdl2java {execution: generate-sources}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org/springframework/core/io/support/ResourcePatternResolver
org.springframework.core.io.support.ResourcePatternResolver
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: org/springframework/core/io/support/ResourcePatternResolver
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
I don't know how to put the springframework-core dependance ?
I tried below like most of answers
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.6</version>
</dependency>
</dependencies>
but it didn't help, I also don't know why it depends on springframework
It works if I put the jar file under $M2_HOME/lib, but is it correct way ? since when I solve this, it requires to add more lib there, can I put it into pom.xml somewhere ?
I tried to put <dependencies/> inside <build> tag, it doesn't work
my maven is 2.2.1 on windows

It works if I put the jar file under $M2_HOME/lib, but is it correct way ?
No, definitely not. To add a dependency, you need to declare it in your pom.xml, something like this:
<project>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>???</version>
</dependency>
...
</dependencies>
</project>
But I don't understand why you would have to add this dependency, spring-core is a dependency of cxf, you should get it transitively. You're not providing enough context information for a more precise answer though.

You have to define it in the pom.xml
Read the docs at http://maven.apache.org/pom.html#Dependencies

You'll need to add this to your Maven pom.xml file in the <dependencies> section:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>???</version>
</dependency>
The version number will depend on which version of spring you're using. (I'm using 2.0 as the version #, along with spring 2.0.8).

Finally I found it by myself, it is due to the error of my springframework-2.5.5 package from local repository. The jar file is not correct. I notice this later in eclipse
Pascal's answer is also correct.
The springframework-2.5.5 is automatically download by maven, unfortunately it is broken, so it still complain the class, and if I put springframework-2.5.6 inside, even it will be downloaded, it will not be used, maven still think it loaded the springframework-2.5.5 into its classpath.
And if I put into %M2_HOME%/lib, surely it will be maven's classpath, and it is wrong to use it.
Since I met this kind of problem before, now I know what it is.
Summary: checking your dependance files to see whether the package is correct
BTW: Thanks for all especially pascal

Related

looking for org.openqa.selenium.support.ui.Select jar path

Can anyone help me to find the link of below jar
org.openqa.selenium.support.ui.Select
How did you add selenium to your project and what IDE are you using?
If you downloaded the jars manually from the selenium website then they're here:
They're in client-combined-3.141.59.jar and when you add it to your IDE you'll have the path you want.
However its not good practice to download and add them manually. You'll be stuck manually upgrading them and having trouble with remote execution.
It's much better if you use maven or gradle to manage this for you.
As one quick example, in maven you add this in you pom.xml:
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
It manages your dependencies for you. You get this in your project:

How to install a plugin in Jira?

I wanted to create a sample servlet as a Jira-plugin according to a tutorial.
I have built the code as it is and I used the following pom.xml to build the code.
When I run the servlet URL I'm getting the following issue about class cast.
[INFO] [talledLocalContainer] ERROR - 13:41:52,368 - com.atlassian.plugin.servlet.DefaultServletModuleManager - [http-bio-5990-exec-4] - Unable to create new reference LazyLoadedServletReference{d
escriptor=com.atlassian.plugins.tutorial.refapp.adminUI:test (null), servletContext=org.apache.catalina.core.ApplicationContextFacade#2829d93e}
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.ClassCastException: com.atlassian.plugins.tutorial.refapp.MyPluginServlet cannot be cast to javax.servlet.http.HttpServlet
[INFO] [talledLocalContainer] at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)
This is possibly a dependency issue in your pom.xml. Check to make sure you are not bundling resources into your plugin that already exist in the environment that is hosting your plugin.
In your case, you might want to check for this:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
With the key part here being <scope>provided</scope> indicating this resource is needed for compilation but does not need to be bundled with the plugin as it is already provided by the runtime environment. If this line doesn't exist or the scope is anything other than provided, then try adding/changing it.
See this page for more info: Dependency Issues during Plugin Initialisation

Exception in deserializing avro object in map reduce

I am trying to run a map reduce job which takes an avro file as input and does some processing. I followed the sample program apache has given us here
http://avro.apache.org/docs/1.7.6/mr.html
But I keep on running into this exception
java.lang.Exception: java.lang.NoSuchMethodError: org.apache.avro.generic.GenericData.createDatumWriter(Lorg/apache/avro/Schema;)Lorg/apache/avro/io/DatumWriter;
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Caused by: java.lang.NoSuchMethodError: org.apache.avro.generic.GenericData.createDatumWriter(Lorg/apache/avro/Schema;)Lorg/apache/avro/io/DatumWriter;
Any idea on what I may be doing wrong? I have specified my pom configs in the bottom. Also I am using MapR version 4.
<repositories>
<repository>
<id>MapR</id>
<url>http://repository.mapr.com/maven/.</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-mapred</artifactId>
<version>1.7.6</version>
<classifier>hadoop2</classifier>
</dependency>
</dependencies>
Common cause of such errors is this:
Your software was compiled against 1.7.6 version of avro, but in runtime, classes from older version were probably loaded.
Make sure that 1.7.6 is the actual version of your avro artifacts in your runtime classpath. Print out the classpath at the start of your mapper. If you're using oozie, the classpath jars are listed in launcher job output.
The first avro jar you see in the classpath is the one that will be used to load the classes, so if it isn't 1.7.6, that's the problem.
You can force your classpath artifacts to come first in the task's classpath by setting mapreduce.job.user.classpath.first configuration property to true.
Also you have another error in your pom that may very well cause you problems, maybe the very ones you're seeing. You are using avro-mapred artifact compiled for hadoop2 while the hadoop artifact you're depending on is that of hadoop1. These should not be compatible. If you're using hadoop1, loose the hadoop2 classifier on avro-mapred, and if you're using hadoop2, remove hadoop-core and put hadoop-mapreduce-client-core instead.
I have solved this by injecting the right Avro jar in bootstrap action, as described here:
https://stackoverflow.com/a/40235289/3487888

Maven ignoring provided scope

I have a EAR with a number of EJB dependencies. 2 of these have a provided scope dependency to the glassfish-embedded-all jar. However when I do a mvn install on my local machine or when the application is build through maven on hudson the ear always contains the glassfish-embedded-all jar.
e.g. DataAccess-ejb with provided dependency
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
Application-ear with ejb dependency
<dependency>
<groupId>com.xxx.yyy</groupId>
<artifactId>DataAccess-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
Any ideas what I am doing wrong or possible suggestions?
Cheers,
James
Try using mvn dependency:tree in order to analyze what artifact is including the glassfish-embedded-all.jar, chances are that you're overlooking something. Maven won't include an artifact that is not declared as as direct dependency and/or inherited through transitive dependency.
You can also issue and mvn dependency:analyze-only command to further clean up those dependencies that you don't really need.
Dependencies with a provided scope are not transitive so you're not getting it transitively, there must be something else. Run mvn dependency:tree from the ear module.
But actually, I really wonder why you're using a provided scope, I think a test scope might be more appropriate. And by the way, I suggest using GF 3.0.1:
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>

Maven classpath order issues

Does anyone know of a way to set a specific classpath order in Maven2, rather than the random ordering I appear to experience at the moment?
There are a number of legitimate reasons for wanting to do this:
A vendor has supplied a patch jar, which contains overriding classes for a previously released jar and therefore the patch jar must appear first in the classpath ordering.
Two jar's found on the classpath discovered by traversing pom dependencies contain the same class in the same package with different signitures. For example:
jboss
jbossall-client
4.2.0.GA
org.hibernate
hibernate
3.1
both contain:
org.hibernate.util.ReflectHelper.class, but the jbossall-client version is missing the getFastClass method.
From googling I see that this is perhaps a point of contention between maven enthusiasts and people facing this particular issue, but surely there are legitimate reasons for classpath ordering.
Any advice from anyone that has solved this particular quandary would be much appreciated!
Thanks
As of version 2.0.9 maven uses pom order for classpath, so you can actually manipulate it now. We mostly supress transitive dependencies to external libraries that we also include directly.
From the release notes of maven 2.0.9:
MNG-1412 / MNG-3111 introduced deterministic ordering of dependencies on the classpath. In the past, natural set ordering was used and this lead to odd results. The ordering is now preserved from your pom, with dependencies added by inheritence added last. In builds that had conflicting or duplicate dependencies, this may introduce a change to the output. In short, if you have weird issues with 2.0.9, take a look at the dependencies to see if you have conflicts somewhere.
Maven 2.0.9 adds correct ordering so you absolutely must have that version or higher for the below to work.
Secondly you need the an updated plugin. The Maven guys are working on a fix, its in their jira to fix but this is something I urgently needed. So in the meantime I have fixed this myself and you can pull the Modified plugin source code from github.
Edit: Refer to http://jira.codehaus.org/browse/MECLIPSE-388
There are two ways to install it, either pull my modified code and install it or download the prebuilt jar and just add it.
Building the plugin
Run maven install from the plugin directory you checked out and then add the following in your plugins section of your projects pom:
<build>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8-cpfix</version>
</plugin>
</plugins>
</build>
Download the jar
Alternatively if you don't want to download and compile yourself then you can just get hold of the jar file and install it yourself.
Once you have the file run
mvn install:install-file -Dfile=<path-to-file> -DgroupId=org.apache.maven.plugins \
-DartifactId=maven-eclipse-plugin -Dversion=2.8-cpfix -Dpackaging=jar
Regardless of how you installed it now when you run mvn eclipse:eclipse it will pick up the modified code and order the dependencies based on the order you defined in your pom file, no alphabetical ordering. It will also put the JRE container at the top of the dependencies.
Hopefully the real version of this code will come out soon, but in the meantime this fix has worked for me on my project and I hope it can help some others as well.
Rather a further qualification of the question than an answer:
under "Maven Dependencies" Eclipse does not seem to honour the POM-order.
(it does use the POM-order under "Java Build Path" & in the Classpath)
Is that the expected behaviour?
I'm using Eclipse 2021-09 (which has Maven 3.8.1 embedded) under Windows 10.
Here's the POM:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.group</groupId>
<artifactId>arty.fact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven Dependency Order</name>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
<exclusions><exclusion><groupId>*</groupId><artifactId>*</artifactId></exclusion></exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
<exclusions><exclusion><groupId>*</groupId><artifactId>*</artifactId></exclusion></exclusions>
</dependency>
</dependencies>
</project>
The Maven Dependencies looks like this:
If you have problem starting with IntelliJ IDEA, you can change the dependencies order from project structrue.