Pom.xml with local jar and concurrent dependency - java

Here is the situation :
I want to use a locally installed jar in a springboot project. I included the dependency to this artifact in my pom.xml :
<dependency>
<groupId>org.mycie.myjar</groupId>
<artifactId>myjar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
This jar uses the artifact snakeyaml with version 1.16
But in my main project, Springboot uses snakeyaml version 1.23
The concurrency seems to cause some issues when running the application.
Do you have any idea on the good practices to tackle this issue?

Maven will only let one of the jars into the resulting application. You can find out by calling mvn dependency:list which jar Maven chose.
The resulting problem cannot be really solved by Maven. Instead, you need to figure out which version of snakeyaml works for all scenarios. Since one of the jars belongs to you, it is probably best to just update the dependency of myjar to avoid this problem.

Related

Maven dependencies for IBM Websphere packages

I'm trying to convert a "classic" JAVA EE project, using IBM websphere 8.0.0.5, into a maven multi module project and facing issues with the IBM dependecies.
We use IBM classes from the following packages:
com.ibm.websphere.asynchbeans
com.ibm.websphere.scheduler
com.ibm.websphere.ce.cm
com.ibm.ws.asynchbeans
com.ibm.ws.util.ThreadPool
To get my local project to be compiled I downloaded the was.installer-8.0.0.pm from IBM and installed it to my maven using
mvn install -f "was.installer-8.0.0.pom" -D serverInstallationFolder="C:\Program Files (x86)\IBM\WebSphere\AppServer"
This step was successfull according to command line output.
I then added the following dependencies to my project as described from IBM:
In parent:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
<version>8.0.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
In module:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
</dependency>
But I still can't compile my project as the IBM packages are not found.
Can anyone help me to find and correct a mistake I made?
Edit
After following BevynQ tip from the comments I copied the "was_public.jar" to "was_public-8.0.0.jar" (described at IBM here) and added it to my repository:
mvn install:install-file -Dfile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.jar" -DpomFile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.pom"
I then changed the dependencies to:
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was_public</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was</artifactId>
</dependency>
This helped to get the compiling errors for the imports to com.ibm.websphere done.
What I now have still open is the packages com.ibm.ws.* package. Anyone have an idea?
Edit 2
I added the following dependency and then I was rid of the com.ibm.ws.* import errors.
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>1.0.0</version>
</dependency>
But it still does not compile as now indirectly references can not be found (in my case commonj.work.WorkManager). It seems I need to add further .jars for every single thing. Isn't there an easier way to provide all websphere jars at once as descirbe in the above linked tutorial with the com.ibm.toolsdependency (which do not work)?
In general, com.ibm.websphere are public API for use by applications (this is true of the packages you listed above) which is consistent with these being in was_public.jar
However, com.ibm.ws package is generally product internals. May I ask what interface methods you are using from the com.ibm.ws.asynchbeans package? Maybe there is a public API alternative.
Regarding commonj.work, the only place I can find this in the WebSphere Application Server product image is WAS/plugins/com.ibm.ws.prereq.commonj-twm.jar so it looks like you will need to use that to compile against.
Here's the solution so I solved my dependency problems:
I configured the company repository manager (nexus) as a mirror. In this nexus all ibm packages are present. As you can think that solved the main problem.
I then added the following dependencies according to common maven style:
Dependencies in pom.xml (version numbers extracted to properties):
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>${ibm.ws.runtime.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.ws.prereq</groupId>
<artifactId>commonj-twm</artifactId>
<version>${ibm.ws.prereq.commonj-twm.version}</version>
</dependency>
Sorry I can't provide a "nice" solution that's useable by all people but the answer from njr and the comment from BevynQ helped at lot to get clearer with the problem and helped to solve the problem in a "more manual" way by copying the needed jars by hand.
I was facing this issue as I tried to build a project using Maven version 3.3.9, running on Java version 1.8.0_101, as depicted in the screenshot:
This is how I resolved it: Step 1. Download the commonj.jar from here.
Step 2. Determine which JDK your Maven is using by typing mvn -version in the command prompt.
Step 3. Go to that directory and place the commonj.jar file there in the jre/lib/ext directory, as shown below. Now your project should build in maven without any issues.

Eclipse showing proper dependencies, but mvn package produces WAR with out-dated dependencies

I'm working with a web app, called A, using maven, in eclipse, going between using m2e eclipse plugin and command line maven.
A depends on a custom library B, which is installed in the local repo. A details this dependency in its pom.xml
When I test the app in eclipse using eclipse's Tomcat, everything is fine -- the up-to-date version of B is used, and I see so in Maven dependencies folder.
But for some reason, when I go to command line and run mvn package, the resulting WAR uses out-dated version of B. I can tell because when I get it deployed to app server, its logging and functionality is broken in a specific way that was fixed in a newer version of B.
Is there any way for me to debug what's going on here? What is eclipse doing that mvn package is not including?
Project definition:
<groupId>org.com.web</groupId>
<artifactId>DocImgTransfer_Servlet</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
Dependency on lib that is somehow getting old version:
<dependency>
<groupId>DocImgTransfer</groupId>
<artifactId>DocImgTransfer</artifactId>
<version>1.0.0</version>
</dependency>
So really 3 questions:
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
Will mvn clean or mvn package -U possibly help in this case at all?
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
a) Is your CustomatJar-1.0.0.jar version that eclipse is referring to same as maven is picking up or is maven picking up an older version?
i.e. Do you own the code for CustomatJar and are you just updating it v/s the one getting packed in war is truly an older version e.g. CustomatJar-0.0.5
i) You could tell by just unzipping the war and seeing which version is packed inside the jar.
ii) mvn dependency:dependency would tell you which dependencies maven command line thinks should be packed. more info
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
Could you server have got an older version of CustomatJar in say it's lib?
You did double check your POM.xml already ... correct?

Eclipse detects wrong maven dependency

I faced with foggy issue.
I am novice in project. I use Eclipse. all my colleagues use IDEA. I have checkout project from svn.
I performed corresponding maven tasks for building and deploying project. all works good.
But my Eclipse shows me problem.
in code:
sceneService.uploadFile(...);
eclipse shows that sceneService hasn't uploadFile method
I began researching. I show this class on PC of my colleague. But there aren't this issue. I noticed that we use different version of jar file of sceneService class.
We use same revision of the pom.xml.
dependency for jar in my pom.xml(for my module):
<dependency>
<groupId>com.day.cq.dam</groupId>
<artifactId>cq-dam-scene7</artifactId>
<scope>provided</scope>
</dependency>
when I type alt+shift+w I see that jar contains sceneService class takes from another module.
I think there is some issue in downloading the correct jar by Maven. your local repository may contain an earlier version of the jar.
Try these commands by going to the root folder of your project from command prompt.
mvn eclipse:clean
mvn eclipse:eclipse
mvn install
if still the problem persists try deleting your local .m2 repository and again rebuilding the project
I think my earlier comments about the "provided" scope are a red herring. The actual problem is likely due to conflicting versions.
By default, Eclipse enables workspace resolution of artifacts. This means it will find artifacts to use (i.e. cq-dam-scene7) from other projects in your workspace. It will also find them in the .m2 repository as well; I'm not sure which takes precedence.
Possible routes towards a solution include:
Specify a version for your artifact. This will ensure you use the correct JAR, even if it has to be found in the local .m2 repository.
<dependency>
<groupId>com.day.cq.dam</groupId>
<artifactId>cq-dam-scene7</artifactId>
<version>1.2.3</version>
<scope>provided</scope>
</dependency>
Ensure your local cq-dam-scene7 project contains the correct code - i.e. a version with the uploadFile() method defined.
I am facing a similar issue, I have two Maven projects in workspace. Main Project is using output JAR of a Helper project as an artifact.
Now the problem is that Main project is trying to Reference JUnit library of Helper project (which has older version 4.10) instead of it's own JUnit library having version 4.12. Because of this in-correct referencing I get build errors in main project.
Only work around which I found is to close the Helper project and have only Main project open in workspace.
Possibly this is an Eclipse bug.
Delete the repository folder in .m2 (in your user dir) and let maven rebuild it in next build cycle.
It will ensure no old jars are cached locally

Created Simpl JAR file, imported to Maven project but Maven install is complainining "package does not exist"

I guess I haven't really had to do this much before because I am running into a strange issue. I am trying to generate a JAR from an existing Java project and then and putting it into a Spring Maven project. I'm sure I'm including it correctly, I have done this many times before with 3rd party JARs that I get (even though its a Maven project I have included some obscure JARs in it and put on buildpath, etc), with my JAR within Eclipse it is showing up fine as if its included, I have a test class that is importing a class from the JAR, instantiating it, etc and its not showing any errors (imports are fine in the IDE, etc), however when I go to do a Maven install I get:
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[11,15] package org.test does not exist
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[21,2] cannot find symbol
I have tried doing a Maven clean but still the same problem, the JAR class I am testing with is this: (was trying a more complex one but then tried this to troubleshoot the issue)
package org.test;
public class something {
public String main () {
return "it is definitely working fine";
}
}
Here is the JAR I generated (with sources visible):
https://docs.google.com/leaf?id=0BzB_xvrbRpbYODQyMjEzOWEtOTdjNS00YjM3LTlkZGUtNjY5NmIwN2RiNTRj&hl=en
I would appreciate any advice as I am rather perplexed and frustrated by this. Thanks
You can include a 'regular' jar in your maven project -just as you described- though it's not a best practice mainly because then you not even lose the functionality of Maven for that jar, but also the whole point of Maven dependency management: you will have to include that jar with your source to make it build.
You can of course also create a Maven artifact for that jar, build it with Maven, install it with Maven and use it as a normal Maven dependency.
You also can create a parent .pom and have your dependency project as a module in it and also your real application (or also your real app can be your parent). See further here.
Since this caused me quite a bit of grief, I figure I should post the solution I found. Apparently you aren't supposed to just include a regular lib JAR in a maven project (although I swear I have done it before and it worked), I found this way to include a local JAR that isn't form a repository from this post:
Can I add jars to maven 2 build classpath without installing them?
I did this and its doing the maven install properly (where version and artifactID are just made up value)
<dependency>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/testjar.jar</systemPath>
</dependency>

Maven stuck on old version of system dependency

My Maven project has a dependency on a non-Maven library, which is coded as a system dependency:
<dependency>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>${foo.version}</version>
<scope>system</scope>
<systemPath>${foo.jar}</systemPath>
</dependency>
where the location of the library can be controlled via local properties:
<properties>
<foo.version>2.1.1</foo.version>
<foo.basedir>/usr/local</foo.basedir>
<foo.libdir>${foo.basedir}/lib</foo.libdir>
<foo.jar>${foo.basedir}/java/foo-${foo.version}.jar</foo.jar>
</properties>
Recently, the library switched from version 2.1.1 to version 2.2.0, so I changed the foo.version property, but Maven seems to be stuck on the old version:
...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example:foo:jar:2.1.1
...
I have run mvn dependency:purge-local-repository (many times, actually). The string 2.1.1 does not appear anywhere in my POM, profiles.xml, or settings.xml. Still, every time I try to build my project, Maven fails with the above error.
What's going on here? Where is Maven storing the dependency version information and how can I update it?
I think the ${foo.version} might be getting resolved as a filter property. Can you check the properties file under src/main/filters.
Not sure if this is indeed the problem but just give it a try and update back.
The other reason that I could think of is - there might be a transitive dependency on com.example:foo:jar:2.1.1. That is some other dependency which needs 2.1.1 version of this artifact. You can find which artifact is bringing this transitively by doing mvn dependency:tree
You know what. Seeing the workaround that #Chris Conway found, I think that this might have been "solved" by simply running mvn clean.
And even if it would not have helped here, it is always worth trying mvn clean when something strange happens.
Dependency version conflict is a very common problem and most of the time when we start building our application, we never focus or generally we forgot on that aspect until and unless our application starts behaving in an unexpected way or getting started some exception.
For readers and visitors of SO who are interested in knowing the reason why dependency conflicts arises and how we can avoid them in our application , I found a source here explained in a precise way ,so i thought of adding my 2 bits to it .
http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/
Cheers

Categories

Resources