gpt4 book ai didi

java - 使用gradle构建时如何解决 'package not found'错误?

转载 作者:行者123 更新时间:2023-12-01 13:02:07 24 4
gpt4 key购买 nike

我正在尝试从源代码构建 TightVNC Java Viewer(我从这里下载了官方版本:http://www.tightvnc.com/download.php)。

使用提供的 gradle 文件构建时,出现此错误:包 com.jcraft.jsch 不存在。

项目中存在文件“src/libs/jsch-0.1.50.jar”。我无法弄清楚为什么它不编译,因为它包含在 build.gradle 文件中。我正在使用 gradle build 命令进行构建。我错过了什么?

这是提供的构建 gradle 文件,最初在 gradle 包中提供:

apply plugin:'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.6
targetCompatibility = 1.6
version = '2.7.2'

project.ext.baseName = 'tightvnc-jviewer'
def buildNo = processBuildNo(version)

defaultTasks 'clean', 'dist'

configurations {
viewerSwingCompile { extendsFrom compile }
viewerSwingRuntime { extendsFrom viewerSwingCompile, runtime }
}

sourceSets {
viewerSwing {
java {
srcDir 'src/viewer_swing/java'
}
resources {
srcDir 'src/viewer_swing/resources'
}
}
main {
java.srcDirs += viewerSwing.java.srcDirs
resources.srcDirs += viewerSwing.resources.srcDirs
}
}

repositories {
flatDir {
dirs 'src/libs/'
}
}

dependencies {
viewerSwingCompile group: 'com.jcraft', name: 'jsch', version: '0.1.+', ext: 'jar'
viewerSwingRuntime configurations.viewerSwingCompile
testCompile group: 'junit', name: 'junit', version: '4.+'
}

def manifestAttributes = ['Main-Class': 'com.glavsoft.viewer.Viewer',
'Implementation-Version': "${project.version} (${buildNo})",
'Implementation-Title': 'TightVNC Viewer',
'Implementation-Vendor': 'GlavSoft LLC.']

jar {
baseName = project.baseName
version = null
manifest {
attributes manifestAttributes
}
def runtimeDeps = configurations.viewerSwingRuntime.collect {
it.isDirectory() ? it : zipTree(it)
}
from(runtimeDeps) {
exclude 'META-INF/**'
}
}

task noSshJar (type: Jar, dependsOn: classes) {
baseName = 'nossh/' + project.baseName
version = null
manifest {
attributes manifestAttributes
}
from sourceSets.main.output
}

artifacts {
archives file('src/web/viewer-applet-example.html')
archives noSshJar
}

uploadArchives {
repositories {
add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) {
addArtifactPattern("$projectDir/dist/${project.baseName}-${project.version}/[artifact].[ext]")
}
}
uploadDescriptor = false
}

task dist(dependsOn: uploadArchives)

def processBuildNo(currentVersion) {
final String VERSION = 'version'
final String BUILD = 'build'

def lastVersion = currentVersion
def lastBuild = 0
def buildNoFile = new File('.build_no')
if ( ! buildNoFile.exists()) {
buildNoFile.createNewFile()
buildNoFile << "${VERSION}=${lastVersion}\n${BUILD}=${lastBuild}"
}
def versions = [:]
buildNoFile.eachLine {
def splitted = it.split('=')
if (splitted.size() == 2) {
def (key, value) = splitted
switch(key.trim()) {
case VERSION:
lastVersion = value.trim()
break
case BUILD:
try {
lastBuild = value != null ? value.trim() as Integer : 0
} catch (NumberFormatException) {}
versions[lastVersion] = lastBuild
break
}
}
}
lastVersion = versions[currentVersion]
if (null == lastVersion) {
versions[currentVersion] = 0
}
++versions[currentVersion]
def outString = ''
versions.each { v, b ->
outString += "${VERSION}=${v}\n${BUILD}=${b}\n\n"
}
buildNoFile.write(outString)
versions[currentVersion]
}

最佳答案

经过多次尝试和错误,我补充道:

compile fileTree(dir: 'src/libs', include: '*.jar')

在依赖项部分下,它起作用了!

关于java - 使用gradle构建时如何解决 'package not found'错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23447620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com