Gradle - 添加目录到类路径
Gradle - add directory to classpath
我的应用程序要求在目录下查找配置文件时,类路径上的 \config
目录可用。我目前有这样配置的依赖项,尽管这可能不是使目录对我的应用程序可用的正确方法:
dependencies {
... //runtime, compile dependencies pulled from repositories
runtime files('config')
}
我正在使用 application
插件为我的项目创建一个独立的 zip。如果我的 \config
目录有 \config\subdir
、file1
、file2
,那么插件会生成具有以下结构的 build\install
目录:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ------|subdir
| ------ file1
| ------ file2
这对我的应用程序不起作用,因为它明确需要一个 \config
目录
然而,这是我需要的目录结构:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ----|config
| ------|subdir
| ------ file1
| ------ file2
如何让 gradle 添加另一个目录到构建中并将其指定为生成的启动脚本的类路径的一部分?
应用程序插件 documentation 说:
Static files to be added to the distribution can be simply added to src/dist
我会尝试将您的配置目录放入 src/dist/lib
并使用 runtime files('src/dist/lib/config')
继续将其添加到您的类路径
注意:解决 this defect 意味着配置必须进入 src/dist
下的 /lib
你可以试试这个:
project('project-name') {
apply plugin: 'application'
mainClassName = "your.main.Class"
startScripts {
classpath += files('src/dist/lib/conf')
}
可以找到更多信息 here。
jar {
manifest {
attributes('Class-Path' : '<directory>' )
}
}
以上对我有用
我的应用程序要求在目录下查找配置文件时,类路径上的 \config
目录可用。我目前有这样配置的依赖项,尽管这可能不是使目录对我的应用程序可用的正确方法:
dependencies {
... //runtime, compile dependencies pulled from repositories
runtime files('config')
}
我正在使用 application
插件为我的项目创建一个独立的 zip。如果我的 \config
目录有 \config\subdir
、file1
、file2
,那么插件会生成具有以下结构的 build\install
目录:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ------|subdir
| ------ file1
| ------ file2
这对我的应用程序不起作用,因为它明确需要一个 \config
目录
然而,这是我需要的目录结构:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ----|config
| ------|subdir
| ------ file1
| ------ file2
如何让 gradle 添加另一个目录到构建中并将其指定为生成的启动脚本的类路径的一部分?
应用程序插件 documentation 说:
Static files to be added to the distribution can be simply added to src/dist
我会尝试将您的配置目录放入 src/dist/lib
并使用 runtime files('src/dist/lib/config')
注意:解决 this defect 意味着配置必须进入 src/dist
/lib
你可以试试这个:
project('project-name') {
apply plugin: 'application'
mainClassName = "your.main.Class"
startScripts {
classpath += files('src/dist/lib/conf')
}
可以找到更多信息 here。
jar {
manifest {
attributes('Class-Path' : '<directory>' )
}
}
以上对我有用