0
我試圖用gradle構建我的項目,但由於某種原因資源被放在與其實際級別不同的級別上。 這裏的身材:Gradle Jar結構與實際項目結構不同
apply plugin: 'java'
version = '1.1'
archivesBaseName = 'DesktopOmegle'
repositories {
//mavenCentral()
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots/'
url "http://repo1.maven.org/maven2"
}
}
dependencies {
compile 'org.json:json:20090211'
compile 'org.fxmisc.richtext:richtextfx:0.6.4'
}
jar {
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'main.java.client.OmegleClient'
}
}
task copyDeps(type: Copy) {
from configurations.runtime
into 'lib'
rename {
String fileName ->
fileName.replace('-20090211', '')
}
}
build.dependsOn(copyDeps)
,這裏是該項目的實際結構(只顯示src文件夾):
|src-
| main-
| java-
| client-...
| server-...
| resources-
| images-...
產生的罐子結構如下:
|jar-
| images-...
| main-
| java-
| client-...
| server-...
| META_INF-...
| org-...
顯然那不是我想要的。我希望jar中的圖像位於main.resources內部,因爲它們是實際的。爲什麼jar沒有堅持項目的真正結構?有人能幫我糾正這種情況嗎?
編輯: 代碼段用於訪問資源:
ClientConstants.RESOURCES = "/main/resources/images/";
if (status.equals(ClientConstants.STATUS_OFFLINE))
{
img = ClientConstants.RESOURCES+"ON.png";
action = "Connect";
}
else
{
img = ClientConstants.RESOURCES+"OFF.png";
action = "Disconnect";
}
Image imageConnect = new Image(getClass().getResourceAsStream(img));
ImageView viewBottom = new ImageView(imageConnect);
這個結構是正確的。什麼是真正的問題? – Opal
images文件夾不在我想要的位置。我希望jar結構與項目結構相同。這意味着圖像應該在main.resources中。那可能嗎? – maxam
可能是,但不符合標準。 – Opal