问题
I am not a java programmer and I am using jSoup in a ColdFusion application, and my java knowledge is limited.
I looked in the docs but could not find a method to tell me which version of jSoup is loaded. Maybe there is a standard java method for that?
It is necessary because I am using it on a shared hosting and I want to ensure I have the correct compatible version loaded.
Thanks, Murray
回答1:
Usually you either supply the java runtime environment with a version of the library you want to use somewhere on the classpath, or you use a build tool to manage dependencies for you.
Typically the latter is preferred.
e.g. I use gradle for just about every project. To add gradle to your project, download/install gradle, open a terminal, cd to the project's root dir, execute gradle init
and then you end up with a few additional files in your project.
One of the files in the project's root dir is build.gradle
this contains many things - one is the project dependencies
. Here's an example of one I use for JSoup projects:
plugins {
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
test { useJUnitPlatform() }
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jsoup:jsoup:1.10.2'
implementation 'com.jayway.jsonpath:json-path:2.4.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
}
Here you can see the exact version of the library dependency and you can check it with gradle dependencies
if you wanted to check for a version clash due to another library importing a different/newer version you weren't expecting.
Another method is simply to download the library and place is somewhere on the classpath so your application can access it.
来源:https://stackoverflow.com/questions/64851787/is-there-a-method-to-get-the-jsoup-jar-version