I've used a 17 version of Guava for my library project and extracted it into the jar. Other project uses my library but it also has a much older version of Guava. When I try to run application, it ignores new Guava and causes errors like
java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.maximumSize(J)Lcom/google/common/cache/CacheBuilder;
How to force my project to use a new Guava and application to use an old?
I am assuming that your project and applications are distinct entities.Also, by Project I assume that you are referring to an Eclipse/IntelliJ/Netbeans project
You would need to set the correct classpaths for the Project and your application separately.
If you are using the IDE to debug your project, your project would need to include the new JAR that you have downloaded. Each IDE has it's own mechanism for adding dependencies to the Project's classpath and hence you would want to refer to the documentation related to that IDE.
For your application you can launch it as java MyApp -cp "path to the old JAR". If you are packaging your application as a JAR, make sure you are packaging the older version of Guava.
Hope this helps.
Edit based on the discussion with the owner of the question
The query here is similar to this SO query. The right way to hence resolve this issue would be either install a Custom ClassLoader or use OSGi
Related
I updated an Eclipse RCP Project from Eclipse 2019-12 to 2020-03. After the update I get build errors on export, like the following:
"The package javax.xml.parsers is accessible from more than one module: , java.xml".
I am using Java 11, no module-info.java file, the Eclipse 3 Compatibility Layer and the eclipse product export wizard in my project.
The error message basically is clear to me. It detects some class twice on classpath, which is not allowed. Once the class is provided by JDK module "java.xml". The second copy comes from javax.xml osgi bundle.
My problem is that both of the packages can not be removed. The JDK module has a lot of dependent JDK modules that are actively used in code and I don't think that they can be supplemented by some libraries. The OSGI bundle is used by a lot of very basic eclipse bundles. So it can also not be removed.
So I have two questions:
Why does Eclipse RCP break projects with its new version? Was that considered a bug before? (I did not find a ticket)
How can I get my project to run again without really big changes?
Edit 1: Added reproducible example:
https://workupload.com/file/wKUZTXJXsR9
Edit 2: See also Eclipse Bug Ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=562761
I created a minimum example. One can see the problem by exporting the product via wizard. I used DocumentBuilderFactory from javax.xml in Application.java to trigger the problem.
I found out a few things:
A plugin dependency to org.eclipse.help.ui is needed to trigger the problem. Although also other plugins have dependencies to javax.xml plugin.
Eclipse tells you the problem in Editor if I you add a direct dependency to javax.xml plugin. But we have only a transitive dependency to it and therefor get no hint.
That raises some new questions:
It seems that org.eclipse.help.ui plugin causes the problem, but we need it in our application. Is this a possible bug? Are there alternatives?
Why does eclipse editor not show the problem if I only have a transitive dependency to javax.xml plugin? Also a possible bug?
I found a workaround for this problem: When using a target definition (*.target file) instead of the Running Platform (automatic target definition of the Eclipse IDE) the error does simply not occur! I don't know exactly what the difference is between these two targets, since they both contain the "javax.xml" bundle. But when using the target file the "javax.xml" bundle is not added to the product file when automatically adding the dependencies and it does not complain later on that this bundle is needed "javax.xml". Somehow when using the target file the "javax.xml" is simply not needed and then no error occurs.
I think there is a bug in Eclipse RCP, that causes this problem when using the Running Platform. But I suggest using a target definition file anyways, since this brings a lot of other advantages.
I am currently using the Eclipse IDE and want to import an external java project so that I can use it in something I am working on. I downloaded the directory of icePDF, found here, and would like to use the java class file "SwingViewBuilder.java" that is found in the directory I linked at "/icepdf/branches/icepdf-6.2.5/icepdf/viewer/src/org/icepdf/ri/common". I have tried some basic things like importing the folder itself, but it did not work.
I would highly suggest using a dependency management tool like Maven or Gradle to download this dependency and any other dependencies you may have into your project for you.
Here is the maven getting started guide: https://maven.apache.org/guides/getting-started/
And here is the maven dependency for you to add to your pom.xml file: https://mvnrepository.com/artifact/org.icepdf.os/icepdf-viewer/6.2.2
If you specifically need version 6.2.5, you will need to build the icePDF project yourself and configure your class path to use it as a dependency.
From hibernate.org: http://hibernate.org/validator/documentation/getting-started/
I saw Prerequisites:
Java Runtime >= 6,
Apache Maven
However, "maven" is not even mentioned in the following:
http://www.aviyehuda.com/blog/2010/04/14/using-hibernate-validator-to-cover-your-validation-needs/
Our current project is not maven-based, a student project. Could we still use hibernate validator without using maven? Or is there any better choice for hibernate validation?
Maven is not required. The main reason you want to use Maven is that it makes downloading all the package dependencies super easy.
If it's just a small student project, and you don't want to use Maven, then just download the jars that you would otherwise have downloaded with Maven.
You can manually download the jar files here : http://hibernate.org/orm/downloads/
Maven is optional. But it's a very helpful tool for building Java projects (via many phases like compile, test, package, install...). You'd better learn to use it.
In your question, the hibernate-validator jar will depend on other jars such as hibernate-jpa, validation-api, joda-time...
It means you can not run your project with only hibernate-validator jar file. You need to collect all the required jars together.
Maven will automatically resolve it for you.
You can download from:
https://repo1.maven.org/maven2/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar
Then add this file jar to your project manually. As you seen, downloading jar file is an alternative way when not using Maven.
This question already has answers here:
How to include libraries in Java without using an IDE
(6 answers)
Closed 8 years ago.
I'm trying to use a java lib to connect to a database, im doing the tutorial outlined here, http://www.homeandlearn.co.uk/java/connect_to_a_database_using_java_code.html
and I can get it to work in netbeans by putting the .jar into the library file in my project file but I don't have a clue how to get it to work hen using an ide such as vim. can someone help?
If I got your question right, you can find the right answer on this other StackOverflow post: how to include libraries in java without using an IDE
You need to build both files into a JAR file, then you can run it.
I hope this helps.
A build tool which features dependency management such as Maven will help solve this problem. To use Maven you will add the location of libraries you require to an XML file (pom.xml) and Maven will download them for you and incorporate them in your target application archive (e.g. a war file).
Maven central provides a means to search for dependencies. In your case you can find the Derby client jar here. Click on the version of the library you would like to use and you'll see the sections of build descriptor code you needs to copy and paste in for: Maven, Ivy, and a few other popular build/dependency management tools.
Once you are comfortable with Maven, you could look up the Maven "Shade" plugin which will help you create a single jar file containing the necessary dependencies to run your application.
Vim, is more of an editor than an IDE, so you will need to specify the library .jar files manually on your class path when running your application.
You can do this by specifying the -cp parameter to the Java executable. e.g.
java -cp driver.jar MyMainClass
The way you are trying to use the library you desired requires manually adjusting your CLASSPATH. Oracle has some detailed instructions on that: PATH and CLASSPATH.
Though, I would suggest to use some kind of build tool which makes it easier to handle your applications dependencies.
In the Java world, the most convenient tools are Ant, Maven and Gradle.
I feel you have just started Java development, so I would prefer Gradle in your case, although Maven is still pretty widely used in projects.
With these build tools handling dependencies will not be -lets say- wired in the IDE and you can easily build your application in any environment.
I use Maven and CouchDB. I put a CouchDB java library dependency in pom.xml and recompile using maven. I see that files get downloaded and the compilation succeeds with no error, but IntelliJ that I use can't find this library or its classes.
I used ektorp, couchdb4j and jcouchdb, but had the same problem. Any help?
If you have opened the project by using [File]->[Open Project...] and then point on the pom.xml then IntelliJ will keep track on changes/updates in the pom.
Do not use the maven-idea-plugin since it is obsolete, last changes are from 2008.
Have a look into a working example and compare it with yours https://github.com/softberries/woodstoxex (couchdb branch), for pure MFN project you can create an IntelliJ project using 'from existing model' option and selecting maven from the list