Java Gradle - 将目录添加到类路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35545405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle - add directory to classpath
提问by Omar Darwish
My application requires that a \config
directory be available on the classpath when it looks for configurations files under the directory. I currently have dependencies configured like so, though this is probably not the correct way to make a directory available to my application:
当我的应用程序\config
在目录下查找配置文件时,它要求在类路径上有一个目录可用。我目前有这样配置的依赖项,尽管这可能不是使目录可用于我的应用程序的正确方法:
dependencies {
... //runtime, compile dependencies pulled from repositories
runtime files('config')
}
I am using the application
plugin to create a standalone zip for my project. If my \config
directory has \config\subdir
, file1
, file2
, then the plugin produces a build\install
directory with the following structure:
我正在使用该application
插件为我的项目创建一个独立的 zip。如果我的\config
目录有\config\subdir
, file1
, file2
,那么插件会生成一个build\install
具有以下结构的目录:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ------|subdir
| ------ file1
| ------ file2
This does not work for my application because it explicitly expects a \config
directory
这对我的应用程序不起作用,因为它明确需要一个\config
目录
However, this is the directory structure that I need:
但是,这是我需要的目录结构:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ----|config
| ------|subdir
| ------ file1
| ------ file2
How can I make gradle add another directory to the build and specify it as part of the classpath for the generated startup scripts?
如何让 gradle 将另一个目录添加到构建中并将其指定为生成的启动脚本的类路径的一部分?
采纳答案by RaGe
The application plugin documentationsays:
应用程序插件文档说:
Static files to be added to the distribution can be simply added to src/dist
要添加到分发中的静态文件可以简单地添加到 src/dist
I would try putting your config directory into src/dist/lib
and continue adding it to your classpath with runtime files('src/dist/lib/config')
我会尝试将您的配置目录放入src/dist/lib
并继续将其添加到您的类路径中runtime files('src/dist/lib/config')
Note: working around this defectmeans that config has to go into /lib
under src/dist
注:工作围绕这一缺陷意味着配置有进入/lib
下src/dist