How to include CSS files of javafx project in gradle assemble?

混江龙づ霸主 提交于 2020-01-16 01:16:33

问题


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

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.

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'
}

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 ...


回答1:


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'
  }

}


来源:https://stackoverflow.com/questions/28940326/how-to-include-css-files-of-javafx-project-in-gradle-assemble

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!