#Re-open java gradle resource
76 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @broken field! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
InputStream s = ResourceFuncUtilities.class.getResourceAsStream("/" + fileName +".png");
check the directory, where compiled class files are - are the resource files in there?
how can I check it?
what ide do you use?
vs code
oh sorry then, I don't know specifics of vs code
ide usually has a directory marked as resource directory. And during compilation it copies all the files from that directory to place with the binary files
Yes that's my problem, if I copy them manually obv it works
"assets/*": [
"./assets/*" // <-- relative to baseURL, so it will resolve to ./src/assets/*
]
``` Found this setting to set assets folder. Did you try using it?
if I right click on resources folder there's an option "Add folder to java source path" but when I click it says please use build.gradle file to manage the sources directories, then even if I'm searching from this morning I can't understand how to add in it.
I don't think that you should make it as source folder. Is there anything like "make it as resource folder"?
also, give a try to add 'assests` settings into gradle
I took it from here
I tried many ways to add the foulder into gradle
but it still keep saying s is null
public static BufferedImage loadSources(final String fileName){
BufferedImage img = null;
InputStream s = ResourceFuncUtilities.class.getResourceAsStream(fileName + ".png");
try {
img = ImageIO.read(s);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return img;
}
this is my full func
I strongly recommend stop using vs code with java. You should use intellij or eclipse
surely ur right but this one I'll continue with vs
btw my structure is
src/main/java
src/main/resources
this should be correct, I mean, resources should be the default resources dir
it should be in build/resources iirc, but I could be wrong
send your buildscript if possible
all the images
and how are you running it? using the gradle application plugin?
if that is the "play triangle" on top right yes
send buildscript
file build.gradle.kts?
yes
yes
send it inside a
```kt
```
block
the "kt" part adds syntax highlighting to make it readable for me
or just send it as a file
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.3/userguide/building_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
java
// Apply the application plugin to add support for building a CLI application
// You can run your app via task "run": ./gradlew run
application
/*
* Adds tasks to export a runnable jar.
* In order to create it, launch the "shadowJar" task.
* The runnable jar will be found in build/libs/projectname-all.jar
*/
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Suppressions for SpotBugs
compileOnly("com.github.spotbugs:spotbugs-annotations:4.7.3")
val jUnitVersion = "5.9.1"
// JUnit API and testing engine
testImplementation("org.junit.jupiter:junit-jupiter-api:$jUnitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
// This dependency is used by the application.
implementation("com.google.guava:guava:30.1.1-jre")
}
application {
// Define the main class for the application.
mainClass.set("i.u.dk")
}
spotbugs {
omitVisitors.set(listOf("FindReturnRef"))
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
your main class is called i.u.dk?
then you're not running it via the gradle run task
the class itself is named myclass, no capitals?
I wanted to kinda censor the package
ah
myclass i mean my class name
alright, so put i.u.dk.myclass (replace as appropriate) for your main class
linux or windows?
windows
run it by doing gradlew.bat run in a terminal
does it work?
perfect
if it's not a problem can u explain me?
is it good from vs code extension?
sure:
basically, when running it with vscode, vscode didn't know about the resources. but, gradle does know about the resources. thus, gradle includes it on the classpath when running it
for developing gradle projects, yes
I have already installed "Gradle for Java" from microsoft
btw I can run just with gradlew run isntead of gradlew.bat run
yeah that works too
here's how to run it in the IDE:
Tasks can be run via:
- Gradle Projects or Recent Tasks tree views
- Run Task command
- Run a Gradle Build command
A running task will be shown with an animated "spinner" icon in the tree views, along with Cancel Task & Restart Task buttons. The Cancel Task button will gracefully cancel the task. The Restart Task button will first cancel the task, then restart it.
Gradle Tasks RunningA task will be run a vscode terminal where you can view the task output.
Send a SIGINT signal (ctrl/cmd + c) in the terminal to gracefully cancel it.
Tasks run via the Run a Gradle Build command are not reflected in any of the tree views. Use this command to specify your own Gradle build arguments, for example to run multiple tasks or to exclude tasks.