如何在gradle汇编中包含javafx项目的CSS文件? [英] How to include CSS files of javafx project in gradle assemble?

查看:303
本文介绍了如何在gradle汇编中包含javafx项目的CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含css文件的javafx项目。我希望它们直接在主java src中:

I have a javafx project including css files. I want them directly in the main java src:

src/main/java/Foo.java
src/main/java/Foo.css

当我现在使用我的gradle脚本来构建一个胖罐时,它确实不包括css文件,运行jar最终在npe。

When I now use my gradle script to build a fat jar, it does not include the css files and running the jar ends up in a npe.

我的gradle脚本如下所示:

My gradle script looks like this:

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

jar {
  manifest { 
    attributes "Main-Class": "foo.Main"
  }
  from {
    configurations.compile.collect {
      it.isDirectory() ? it : zipTree(it)
    }
    configurations.runtime.collect {
      it.isDirectory() ? it : zipTree(it)
    }
  }
}

repositories {
  mavenCentral()
}

dependencies {
  compile 'com.github.sarxos:webcam-capture:0.3.10'
}

如何从gradle获取可运行的jar文件?
我已经尝试明确包含css文件 - 它没有用/我做错了...

What can I do to get a runnable jar file from gradle? I tried already to explicitly include the css files - it did not work / I did it wrong ...

推荐答案

如果您无法将资源文件更改为资源目录,则可以使用:

If you can't change your resource files to a resource directory, then you can use:

jar {
  manifest { 
    attributes "Main-Class": "foo.Main"
  }
  from {
    configurations.compile.collect {
      it.isDirectory() ? it : zipTree(it)
    }
    configurations.runtime.collect {
      it.isDirectory() ? it : zipTree(it)
    }
  }

  from('src/main/java') {
     include '**/*.css'
  }

}

这篇关于如何在gradle汇编中包含javafx项目的CSS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆