I have been trying to find a way to BouncyCastleProvider in Java 11 from openjdk. Since there is no ext folder, I can't figure out where to put the jar file. I am using gradle build on MacOS Catalina. It will really help if someone can help me out on this.
I am getting the following error while running gradle build. I have dependency mentioned in gradle as well.
java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
You can use the way you import all your other gradle dependencies.
For example with the dependency:
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.64'
Taken from:
https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.64
(Where you can find other versions if you need them)
If you're unsure how to import gradle dependencies I'd suggest searching Stackoverflow, as I'm sure that been asked many times before.
For example:
How to import external dependencies in gradle?
EDIT: You added another error. Could be the path of the jar needs to be added / classpath.
If you want to add the JAR to your ide, which I guess is Gradle Build Tool if I understood you right. They speak of how to do it here:
How to add local .jar file dependency to build.gradle file?
Related
I know Java pretty well and am an experienced C/Python programmer, but I may have some fundamental misconceptions when it comes to Gradle.
I'm developing in the terminal and vim, it's just who I am. I have Apache Derby set up on my system: downloaded, environment variables set, etc. I wish to use this in my Java project which I'm building with Gradle, but I don't know how to include it in the dependencies other than from the Maven repository.
If I do:
testCompile group: 'org.apache.derby', name: 'derby', version: '10.5.3.0'
My understanding is that this downloads it from the Maven repo again. Am I going about things the wrong way by wanting to use my system Derby, or is there a way to point Gradle to it? If this question is riddled with misconceptions I would appreciate them being put straight.
Thanks.
+1 for using vim/terminal, that is cool! 😎
Gradle is extremely flexible and will do whatever you ask - although there are best practices, see below. You can have a libs/ folder with all your libraries in it, and point Gradle to it:
dependencies {
implementation fileTree('libs') { include '*.jar' }
}
This will add all JARs in the libs/ folder to your classpath. Gradle calls this a file dependency. The libs folder does not have to be in your project directory, so yes, you can point to your system-wide libs, too.
However.
Gradle has a very advanced caching mechanism, which will minimize network usage and even balance this with local storage requirements. It will also reliably share downloads between projects. You want to use this.
Also, many Java libs have dependencies of their own ("transitive dependencies"), often quite a lot of them, resulting in whole trees of dependencies. Since the transitive closure of all of them will end up on your classpath, there can be conflicts, which Gradle will resolve for you. You will not want to perform manual dependency resolution.
Plus, your project will be easier to compile for others because Gradle will make sure the dependency is loaded and present. Whereas a "system derby" would need to be installed in some other way before running Gradle.
File dependencies have a myriad of other problems as well, so I would urge you to have Gradle handle this for you and use the syntax from your question:
dependencies {
implementation group: 'org.apache.derby', name: 'derby', version: '10.5.3.0'
}
Here's a little more info on so-called "configurations", like testCompile and implementation to help you choose the right ones.
All of this will work perfectly with Vim and terminal. So well in fact that I often call Gradle from a terminal while developing in IntelliJ. 😊
I'm still fairly new to development and don't know how to solve my problem.
I have a project that needs other code for it to work.
I understand that by adding a path n the import section of my java gives access to a library.
I also understand that by adding a compile dependency to my build.gradle file, tells it where that library is.
My question is two part:
What do I do when it fails to resolve dependency?
I have downloaded the source code off of git hub.
I want to be able to add the source to my project.
Now, I don't want to add it directly to my package, but the way gradle does it. Just by pointing to it.
So my real question, how do I get a library into my code without adding the entire source code into the package?
What would I have to do in my import section of my java file?
P.S.
Thanks in advance.
Since I'm still learning the concepts, my question might not be structured in the best manner.
You could create a jarfile from the those sources:
jar cf program.jar -C path/to/classes .
source: https://stackoverflow.com/a/18146453/7625131
further information: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html
After that you just have to reference it using gradle:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'gson-2.2.4'
}
source: https://stackoverflow.com/a/20700183/7625131
As Mett highlighted. Create a jar of the project that you cloned from github. Add it in the buildpath of your desired project . If you are using a build automation tool like maven or gradle , then install the jar in your local repository. Then use it as a dependency in your project.
I'm building a java application with Intellij-idea, Gradle and Mongo. I created a new Gradle project and I was having some trouble importing mongodb-java-driver inside my project. I modified this piece of code inside build.gradle:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.mongodb:mongo-java-driver:3.4.1'
}
But was unable to use Mongo with Java. My External Libraries didn't have any Mongo jar. Then I saw here that I should add the application plugin to my build.gradle. I searched on the official docs that this plugin "will automatically add run task that will execute the specified main class with all the runtime dependencies automatically put on the classpath:" as the answer linked above stated. But this didn't solved my problem.
Then I added the idea plugin, since I saw here that "The IDEA plugin generates files that are used by IntelliJ IDEA, thus making it possible to open the project from IDEA". I didn't think that would help me but was worth a try. Unfortunately, this didn't helped either.
After this I saw here that I should synchronize my project. Since I created this from zero and didn't import any complete project from outside I didn't understand why I should synchronize it. While it was synchronized, I saw Intellij was downloading mongo-java-driver. After that, I still was unable to use Mongo. I had to add the downloaded jar to my project class path, as this was one of the suggested corrections given by Intellij.
I've come from Eclipse/Maven and I'm discovering how Intellij/Gradle behave. So my question is what is strictly necessary to use mongodb-java-driver on Intellij/Gradle and why I had to synchronize my project? Is this the correct way of using Gradle? Always building and synchronizing after?
I want to preface this with I am still new to gradle and hopefully someone can clarify any misconceptions I might have.
I have a gradle build script that compiles my project and builds into a RPM. In one of my subprojects I have the following snippet:
dependencies {
provided libraries.stormCore
}
where libraries.stormCore is just a map literal with the stormCore pointing to the maven dependency object 'org.apache.storm:storm-core:0.10.0'
However, once my project compiles I am seeing in my jar defaults.yaml which comes from the stormCore library and I was under the impression provided would not add any of the dependencies into the jar. This is causing storm to start erroring with multiple defaults.yaml found. provided comes from the nebula-provided-base package.
Thanks in advance
I have this line in my code:
import org.apache.commons.lang.StringUtils;
I downloaded the Apache Commons Lang 2.6 zip from http://commons.apache.org/proper/commons-lang/download_lang.cgi. There were two choices for Binaries, 1) commons-lang-2.6-bin.tar.gz and 2) commons-lang-2.6-bin.zip. I downloaded the second one and then extracted it. Then I went to the properties for my project and added the commons-lang-2.6 JAR file to my build path (there were two others - javadoc & sources). Then I go to my command prompt and try to do a gradle clean build to see if I'll get a successful build and it says error: org.apache.commons.lang does not exist. Any help to get rid of this error? I'm using myEclipse and it doesn't give me that error, only my cmd does.
If i understand correctly, you added the jar in your eclipse build path. However, this usually doesn't mean you added it to you gradle build script, which means gradle doesn't know about the commons-lang jar file, only eclipse does.
To add it to gradle, you should add it to the build.gradle file, more or less as follows :
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
}
Maybe you could try using a gradle plugin for ecplise, like https://github.com/spring-projects/eclipse-integration-gradle/ to automate or make easier to keep ecplise and the gradle script in sync.
Make sure that the classpath for your build script is properly defined.