#using installDist .bat file (as compiled version) but it messes up file paths

1 messages ยท Page 1 of 1 (latest)

strong ivyBOT
#

<@&987246399047479336> please have a look, thanks.

strange sky
#

(Gtg now so ill check back in about 7 hrs)

west smelt
#

What is not working anymore?

strange sky
#

I'm trying to get it to run with the build.gradle dependencies but it doesn't work. Only works with the raw files which don't work when compiled into a jar file

#

with OpenCV

west smelt
#

And do you get any error?

strange sky
#
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve org.opencv:opencv:4.12.0.
     Required by:
         root project 'JavaMacroTool'
      > No matching variant of org.opencv:opencv:4.12.0 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 25, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally but:
          - Variant 'releaseVariantReleaseApiPublication' declares a library for use during compile-time, and its dependencies declared externally:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, preferably in the form of class files
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 25)
          - Variant 'releaseVariantReleaseJavaDocPublication' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 25)
          - Variant 'releaseVariantReleaseRuntimePublication' declares a library for use during runtime, and its dependencies declared externally:
              ```
#
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 25)
          - Variant 'releaseVariantReleaseSourcePublication' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 25)```
#
* Try:
> No matching variant errors are explained in more detail at https://docs.gradle.org/9.1.0/userguide/variant_model.html#sub:variant-no-match.
> Review the variant matching algorithm at https://docs.gradle.org/9.1.0/userguide/variant_attributes.html#sec:abm_algorithm.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to generate a Build Scan (Powered by Develocity).
> Get more help at https://help.gradle.org.
BUILD FAILED in 28s
1 actionable task: 1 executed
#

sorry for the mutliple files it wasn't letting me send the error as a .txt (laptop hella buggy) and was to big to send as one

west smelt
#

Why do you have your opencv dependency declared 3 times with different scopes? implementation should also cover the other 2.
It does not seem to be able to resolve the dependencies as the dependency list in your image also shows. So for now try to only use implementation to see if ti solves the issue

strange sky
#

i tried looking up some videos on how dependancys work and tried stuff but i get that same error

#

weird thing is, i got it working with using the dll and jar file for openCV but not the other way

west smelt
#

It seems like it tries to use the android binaries, or something like that. Try using that implementation 'org.opencv:opencv:4.12.0@jar'

#

Otherwise you can also use the downloaded jar file with implementation files('libs/opencv-4.12.0.jar')

#

Just copy to jar into the project

strange sky
#

I did the libs/files and it didn't load, i thought it was a gradle thing but if its not ill try fix that

#

(when i get the chance)

#

also, how do i use the build.gradle to choose which file it runs when it builds the jar
like what file is called so it doesn't just perform nothong @west smelt

west smelt
#

You don't.
If you want to continue using gradle I suggest you to switch to the Kotlin DSL. Rename you gradle build file to build.gradle.kts. It has a slightly different syntax but is much better in terms of usability. Then add the distribution plugin which builds you a proper distribution of you app. Then you just need to execute a bat/shell script to run your application

strange sky
west smelt
#

yes

strange sky
#

ok

strange sky
# west smelt yes
plugins {
    id("java")
    id("application")
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
    implementation(files("libs/opencv-4120.jar"))
}

tasks.test {
    useJUnitPlatform()
}

application {
    mainClass.set("org.robot.macroFunctions")
}

tasks.jar {
    manifest {
        attributes(
            "Main-Class" to "org.robot.macroFunctions"
        )
    }
}

i got this, it doesn't give any errors but when i create a jar file it, the jar file does nothing when run
so is there any way to run a .jar and see if there is anything wrong with it?

strong ivyBOT
spice hedge
#

You don't need the tasks.jar part, that's what the application plugin does and why you specify it in the application block. If you have a module-info then you can add to application blockmainModule.set(modulename) as well as applicationDefaultJvmArgs.set(listOf())

#

The try gradlew run

strange sky
#

alright, i ran this and then jar (under the build folder tasks in gradle):

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader in an unnamed module (file:/C:/Users/Parad/.gradle/wrapper/dists/gradle-9.1.0-bin/9agqghryom9wkf8r80qlhnts3/gradle-9.1.0/lib/native-platform-0.22-milestone-28.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled


> Task :compileJava
Note: C:\Users\Parad\Downloads\java-macro\pytorchmacro\src\main\java\org\robot\macroFunctions.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :run
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.robot.macroFunctions in an unnamed module (file:/C:/Users/Parad/Downloads/java-macro/pytorchmacro/build/classes/java/main/)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

OpenCV version:4.12.0
debugMode:enabled
teamsCallLoop Activated

[Incubating] Problems report is available at: file:///C:/Users/Parad/Downloads/java-macro/pytorchmacro/build/reports/problems/problems-report.html

BUILD SUCCESSFUL in 33s
3 actionable tasks: 2 executed, 1 up-to-date
Consider enabling configuration cache to speed up this build: https://docs.gradle.org/9.1.0/userguide/configuration_cache_enabling.html
PS C:\Users\Parad\Downloads\java-macro\pytorchmacro> 

but it still makes a .jar that doesn't do anything or give any error or anything

strong ivyBOT
strange sky
#

here is the .jar it creates

strange sky
# strange sky

for context it creates this UI, but only when running macroFunctions.java and not working with the .jar file

spice hedge
#

My bad, I think application plugin doesn't inject mainClass into the jar, so ignore that advice.

#

You're talking about double clicking your jar file and it not working?

#

That's related to your system not associating it with java.

strong ivyBOT
strange sky
#

C:\Users\Parad>java -version
java version "25" 2025-09-16 LTS
Java(TM) SE Runtime Environment (build 25+37-LTS-3491)
Java HotSpot(TM) 64-Bit Server VM (build 25+37-LTS-3491, mixed mode, sharing)

#

and its java 25

spice hedge
#

When you click on a .txt file, a program opens up. How does windows know which program to open up. There is a list it maintains that ASSOCIATES file name endings with installed programs (e.g. wordpad, java)

#

I guess this jarfix program programmatically does this for you but somewhere in windows settings you can get that list.

strange sky
#

i just tested another jar file for a public program and it worked, so its def the file itself
not that the file isn't using java correctly ( i think)

spice hedge
#

So it has the mainclass in the manifest? Is this the only jre you have installed.

#

Try that jarfix thing, it must work since it's a tag on this server.

#

Or you can make a standalone

spice hedge
#

I've seen people here say it works

spice hedge
strange sky
#

k

spice hedge
#

might be that it's currently only associated with older java runtime you have installed and thus crashes out if it needs java25 or some other newer java.

#

Is this javafx?

strange sky
#

Tried jarfix and still nothing

spice hedge
#

Is this javafx?

strange sky
# spice hedge Is this javafx?

Im not using any javafx
i double checked and there are 0 mentions of javafx in my entire program so i think im alright

spice hedge
#

When you go into Settings->System-> type defaultApps in search bar.->scroll down and click on "choose default apps by file type"

#

window settings that is.

#

is there an entry for .jar?

strange sky
#

doesn't mention version however

spice hedge
#

if you click on it does to go to it's location?

strange sky
#

nah it does this

spice hedge
#

Yea, it's only showing apps installed through windows. Like an installer.

#

Do you have another jdk/jre like 1.8 installed in windows

#

Which would be this one it refers to?

strange sky
# spice hedge Do you have another jdk/jre like 1.8 installed in windows

found a 21.0.8 that wouldn't show anywhere else

(c) Microsoft Corporation. All rights reserved.

C:\Users\Parad>where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe

C:\Users\Parad>java -version
java version "25" 2025-09-16 LTS
Java(TM) SE Runtime Environment (build 25+37-LTS-3491)
Java HotSpot(TM) 64-Bit Server VM (build 25+37-LTS-3491, mixed mode, sharing)

C:\Users\Parad>




strong ivyBOT
spice hedge
#

That's how we used to do it in the old days, modify the registry but I think they disallowed setting file associations that way in windows 10.

#

Actually I think I had a program to do it.

#

I looked on mine and I don't have a .jar association on this 13yr old install.

#

You can try jpackage, to make a .exe

strange sky
spice hedge
#

gradlew jpackage

strange sky
#

FAILURE: Build failed with an exception.

  • What went wrong:
    Task 'jpackage' not found in root project 'JavaMacroTool'.
strong ivyBOT
#

Due to the JVM and bytecode as intermediate execution stage, turning a Java application into a standalone executable (exe, msi, deb, rpm, dmg, pkg) is not trivial.
However, there exist various tools to do the job. They mostly differ in the details of the solution they create and hence also in their purpose:

  • jpackage (the official tool) - creates an installer
  • Launch4J - creates a wrapper executable that unwraps on execution
  • GraalVM - attempts to create an actual native executable instead of wrappers or installers

This guide explains how to use jpackage, an official tool that is available in all JDKs since Java 16. The tool creates an installer for the application, so the end-user will get an executable that guides them through a setup where they can select installation path and tweak other settings, finally resulting in the application being installed on the machine (with a proper uninstaller, desktop shortcuts, start menu entries, ...): https://i.ibb.co/8Kn20fS/2V5ovUu.png

As an example, suppose you have a fat jar of your application called HelloWorld.jar, with a main class called Main. Put the jar into a dedicated release folder for simplicity. Execute the following command and you have an installer for your application in a folder called installer:

jpackage --input "release" --dest "installer" --main-class "Main" --main-jar "HelloWorld.jar" --name "HelloWorld" --win-dir-chooser --win-menu --win-shortcut --type exe

See the official documentation for more information on the available commands and for other operating systems:

Here is an example for a more complex setup which also associates file endings to the application, has a custom icon and more: https://pastebin.com/cfzqSKnW

strange sky
#

ty

spice hedge
#

I've only ever tried in a javafx gradle build. There was no specific plugin required but...

#

ok I looked at that project it was using this beryx plugin.

plugins {
    java
    application
    id("org.openjfx.javafxplugin") version "0.1.0"
    id("org.beryx.jlink") version "3.1.2"
}
#

With this jlink block

jlink {
    imageZip.set(layout.buildDirectory.file("/distributions/app-${javafx.platform.classifier}.zip"))
    options.set(listOf("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages"))
    launcher {
        name = "app"
    }
}
#

and jpackage makes an .exe in the build folder. Actually don't need that jlink block I think.

strange sky
#

is it like some extension to jpackage or its own thing

spice hedge
#

yea, try it. put that plugin in the plugins block like I had above and then skip the jlink block and just try gradlew jpackage

strange sky
#

when i build i get this with both jpackage and jlink:


An exception occurred applying plugin request [id: 'org.beryx.jlink', version: '3.1.2']
> Failed to apply plugin 'org.beryx.jlink'.
   > Cannot add task 'jpackage' as a task with that name already exists.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to generate a Build Scan (Powered by Develocity).
> Get more help at https://help.gradle.org.
BUILD FAILED in 198ms

when i do without jpackage and only jlink i get:

> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.panteleyev.jpackageplugin:org.panteleyev.jpackageplugin.gradle.plugin:1.7.6.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/panteleyev/jpackageplugin/org.panteleyev.jpackageplugin.gradle.plugin/1.7.6/org.panteleyev.jpackageplugin.gradle.plugin-1.7.6.pom
     Required by:
         root project 'JavaMacroTool'

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
#
    id("java")
    id("application")
    id("org.panteleyev.jpackageplugin") version "1.7.6"
    id("org.beryx.jlink") version "3.1.2"
}```
and
```plugins {
    id("java")
    id("application")
    id("org.beryx.jlink") version "3.1.2"
}```
spice hedge
#

no get rid of that panetleyev one.

strange sky
# spice hedge no get rid of that panetleyev one.

doing that gives this error (like shown above):

> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.panteleyev.jpackageplugin:org.panteleyev.jpackageplugin.gradle.plugin:1.7.6.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/panteleyev/jpackageplugin/org.panteleyev.jpackageplugin.gradle.plugin/1.7.6/org.panteleyev.jpackageplugin.gradle.plugin-1.7.6.pom
     Required by:
         root project 'JavaMacroTool'

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

spice hedge
#

clean

strange sky
#

k

#

still happens

spice hedge
#

you removed that panteleyev plugin?

strange sky
spice hedge
#

are you using intellij?

strange sky
#

yes

#

i can send the github page if its any help

spice hedge
#

Is there a sync button you didn't hit?

strange sky
spice hedge
#

Like wix toolset or something like that?

strange sky
#

wix toolset?

spice hedge
#

try clicking on jpackageImage

strange sky
#
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.panteleyev.jpackageplugin:org.panteleyev.jpackageplugin.gradle.plugin:1.7.6.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/panteleyev/jpackageplugin/org.panteleyev.jpackageplugin.gradle.plugin/1.7.6/org.panteleyev.jpackageplugin.gradle.plugin-1.7.6.pom
     Required by:
         root project 'JavaMacroTool'

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

spice hedge
#

I can see that panteleyev shit in your screen shot

#

is that dependencies

strange sky
#

forgot abt dependancys lol

#

sorry abt that

#

build is fixed but jpackage command isn;t

> Error while evaluating property 'moduleName' of task ':prepareModulesDir'.
   > Failed to query the value of extension 'jlink' property 'moduleName'.
      > Cannot find module-info.java in [C:\Users\Parad\Downloads\java-macro\pytorchmacro\src\main\java]

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to generate a Build Scan (Powered by Develocity).
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 10.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/9.1.0/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 6s
7 actionable tasks: 4 executed, 3 up-to-date
strong ivyBOT
spice hedge
#

Ok, so you don't have a module-info.java file

#

right-click on your src/main/java in project view and choose New -> then module-info.java. See if it fills one out for you.

spice hedge
#

I have ultimate intellij so not sure if same as what you ahve but it throws up a bar saying "Fill in module dependencies"

strange sky
#

one sec

spice hedge
#

alt-enter should bring up a menu with that too

strange sky
#

i think i missed something

spice hedge
#

or right click somewhere in module file and choose context actions

#

You should have a module-info file with at least module somename{} right?

strange sky
spice hedge
#

not under your packages, out side of, along side it.

#

src/main/java/module-info.java

strange sky
#

sorry i don't get it

spice hedge
#

right click on that blue java folder icon, a menu comes up, Choose new-> you should see another menu I think, find module-info.java

strange sky
#

got it

#

it did auto fill

spice hedge
#

so try jpackage or jpackageImage

strange sky
#
    requires opencv;
             ^```

so the file version is the only one that works, but i think this wants something extra or the other method of adding it that would always try use a android version
strong ivyBOT
spice hedge
#

is it supposed to be requires org.opencv?

strange sky
spice hedge
#

hmm, maybe it's that jar file dependency

strange sky
#

implementation(files("libs/opencv-4120.jar"))
this one?

spice hedge
#

yes

#

you had implementation org.opencv:opencv:4.12.0, try that again

strange sky
#

if i go back to that i get the same old error where it tries to find a android jar

> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve org.opencv:opencv:4.12.0.
     Required by:
         root project 'JavaMacroTool'
      > No matching variant of org.opencv:opencv:4.12.0 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 25, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
          - Variant 'releaseVariantReleaseApiPublication' declares a library for use during compile-time, and its dependencies declared externally:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, packaged as a jar
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 25)
          - Variant 'releaseVariantReleaseJavaDocPublication' declares a component for use during runtime, and its dependencies declared externally:
spice hedge
#

It looks like you have to use a different dependency. (I asked chatgpt!)

    implementation 'org.bytedeco:opencv:4.10.0-1.5.10'
    implementation 'org.bytedeco:opencv-platform:4.10.0-1.5.10' // includes native binaries for all OSes
#

use that instead of the implementation 'org.opencv:opencv:4.12.0'

strange sky
#
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.bytedeco:opencv-platform:4.10.0-1.5.10.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/bytedeco/opencv-platform/4.10.0-1.5.10/opencv-platform-4.10.0-1.5.10.pom
     Required by:
         root project 'JavaMacroTool'

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

spice hedge
#

maybe chat got the versions wrong, you can look it up.

#

Those are latest from june

strange sky
#

it downloaded a bunch of stuff but still led to

    requires org.opencv;
                ^```
strong ivyBOT
spice hedge
#

so go back to just requires openvc

strange sky
#

doesn't work either, tried that right after trying org. in front

spice hedge
#

I'm barely awake. remove it

strange sky
strange sky
#

should i just send the github and see if anyone else knows whats going on?

spice hedge
#

I meant the entire module-info.java file. Just rename it to schmodule-info.java and see ifyou can get a jar file that works on double click.

#

It was jpackage that wanted the module-info file

strange sky
#

error: module declarations should be in a file named module-info.java
module JavaMacroTool.main {
^
i don't get what renaming is gonna do

spice hedge
#

not sure why they gave it a .java extension.

strange sky
#

it can be double clicked but defaults to java 21, just like before

surely there must be some way to make it auto-run with 25 if possible

spice hedge
#

Does it need java25 though?

strange sky
#

yup

#

i could try uninstall java 21

spice hedge
#

You downloaded java25 via intellij? I wonder if that jarfix relies on a JAVA_HOME setting.

strange sky
#

i think this could work if i reinstall this way

#

(as u can see even the unistaller can't detect it)

spice hedge
#

echo %JAVA_HOME% in a cmd.exe

strange sky
#

C:\Users\Parad>echo %JAVA_HOME%
%JAVA_HOME%

C:\Users\Parad>echo %JAVA_HOME%
%JAVA_HOME%

C:\Users\Parad>

spice hedge
#

Chat says you can run jarfix from cmd.exe and point to jdk not installed with msi.

#

jarfix.exe /k "C:\path\to\jdk-21\bin\javaw.exe"

#

I just accidentally posted some relavant info in chit-chat

#

Ability to associate filetype (.jar) is hidden at the bottom of the scroll

#

right click on teh jar file, open with, choose more apps

#

then scroll down all the way adn you'll see there is a link to choose a file directly (javaw.exe)

#

"Look for another app on this pc"

strange sky
#

i see

#

i just gotta fix intellij because reinstalling java 25 just broke it even more

spice hedge
#

I have to go to bed, I hope one of those two things works.

strange sky
#

thanks for all your help btw

strange sky
#

got it to run with java 25 in cmd:
C:\Users\Parad>"C:\Program Files\Java\jdk-25\bin\java.exe" -jar "C:\Users\Parad\Downloads\java-macro\pytorchmacro\build\libs\JavaMacroTool-1.0-SNAPSHOT.jar" no main manifest attribute, in C:\Users\Parad\Downloads\java-macro\pytorchmacro\build\libs\JavaMacroTool-1.0-SNAPSHOT.jar

its missing main manifest attribute but i already have mainClass.set("org.robot.macroFunctions")

    id("java")
    id("application")
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
    implementation("org.bytedeco:opencv-platform:4.11.0-1.5.12")
}

tasks.test {
    useJUnitPlatform()
}

application {
    mainClass.set("org.robot.macroFunctions")
}
#

maybe the file location is wrong?

west smelt
#

I haven't read the conversation since we talked yesterday. Why are you executing the jar instead of the distribution that is being built? Execute the gradle command installDist and then in build/install/<project_name>/bin you will find the start files. On windows execute the bat file.

strange sky
strong ivyBOT
strange sky
#

using installDist .bat file (as compiled version) but it messes up file paths

strange sky
#

one sec

#
    public static void takePartialScreenshot(String threadName, int part) throws IOException {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();

        // Full screen bounds
        Rectangle screenRect = gc.getBounds();

        // Taskbar/dock insets
        Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);

        // Adjust for taskbar/dock
        int usableX = screenRect.x + screenInsets.left;
        int usableY = screenRect.y + screenInsets.top;
        int usableWidth = screenRect.width - screenInsets.left - screenInsets.right;
        int usableHeight = screenRect.height - screenInsets.top - screenInsets.bottom;

        // Calculate halves based on *usable* screen size
        int halfWidth = usableWidth / 2;
        int halfHeight = usableHeight / 2;

        // Define the 4 parts:
        // 1 | 2
        // -----
        // 3 | 4
        Rectangle partRect;
        switch (part) {
            case 1 -> partRect = new Rectangle(usableX, usableY, halfWidth, halfHeight); // top-left
            case 2 -> partRect = new Rectangle(usableX + halfWidth, usableY, halfWidth, halfHeight); // top-right
            case 3 -> partRect = new Rectangle(usableX, usableY + halfHeight, halfWidth, halfHeight); // bottom-left
            case 4 ->
                    partRect = new Rectangle(usableX + halfWidth, usableY + halfHeight, halfWidth, halfHeight); // bottom-right
            default -> throw new IllegalArgumentException("Part must be 1, 2, 3, or 4");
        }

        // Capture only that region
        BufferedImage screenImage = bot.createScreenCapture(partRect);

        // Save it
        File outputFile = new File("src/main/resources/images/screenshot/screenshotPart" + part + "Thread" + threadName + ".png");
        ImageIO.write(screenImage, "png", outputFile);
    }```
strong ivyBOT
# strange sky

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

strange sky
#

Those 2 functions

#

its something to do with how file paths are used when complied to a .bat

signal dew
#

You shouldn't be trying to write into src paths... those wouldn't exist if you only distribute the compiled application.

strange sky
signal dew
#

Either as a location relative to the user's profile, or an application installation or work folder.

#

resources and source files are used to build the distribution (usually a jar) that is passed to the JVM to run the application - it's not a file-system, and you'll need some form of storage to store content managed at runtime.

strange sky
#

what im confused about, is how im going to put files somewhere that can be used by both uncomplied and the compiled .bat version
like i would have to add the files myself to the .bats location i guess and change some stuff but i just don't know how to do both

signal dew
#

a .bat file isn't ever 'compiled'... it's a script.

strange sky
#

yeah, i know but its what i mean

#

it still simplifies the files down a lot, which makes it better for releases

#

and doesn't need a IDE or jarfix

signal dew
#

Batch files can reference paths relative to themselves. If you're distributing your jar file a a batch file to launch it (requiring a JDK too) then you can bundle the images and other files alongside it.

strange sky
#

bc if its based off where the .bat is, wouldn't that be different to basing it off where the .jar or the java files are

signal dew
#

I don't understand why you need to 'replace' a path. If the path is in a known relative position to the .bat file, then you can work out the path.

strange sky
#

bc your in a different file structure

signal dew
#

The Java files aren't something you distribute, the jar file is (containing the class files compiled from Java and resource files)

#

One option, when invoking java from the batch file, would be to pass the 'home path' as Java system property to the Java program. This way, the program's 'working folder' doesn't have to change.

And the program can load all of its files relative to that 'home path'.

strange sky
#

home path for me would be inder pytorchmacro [JavaMacroTool] right?
so if the files are in the "files" folder (i couldn't think of a better name) as shown, if i copy+paste that same files folder beside the .bat would it be able to read those with the same path, which is based on the "programs working folder"

signal dew
#

A batch file can read its own path

Something like (I haven't used batch files for a while)

@echo off

SET BASE_PATH="%~dp0"

echo "My path is %BASE_PATH%"
strange sky
#

like this? set APP_HOME=%DIRNAME%..

signal dew
#

If the application home is the same folder as where the batch file is, then the %~dp0 is that path.

#

%0 is the batchfile full path and drive, including the batchfile name. ~d extracts the drive letter and ~p extracts the path... %~dp0 is therefore the drive and path of the batch file.

#

So if your application folder was

...someplace...\
    launch.bat
    jdk\
       ...
    lib\
       foo.jar
       bar.jar
    images\
       ...

Then you could do something like

@echo off

set BASE_PATH="%~dp0"
set LOCAL_JDK="%BASE_PATH%"\jdk

"%LOCAL_JDK%"\bin\java.exe -cp "%BASE_PATH%"\lib\*.jar -DAPP_HOME="%BASE_PATH%" some.application.Main

And your application could look up String appPath = System.getProperty("APP_HOME") to look for Path.of(appPath, "images")

#

No idea if all that escaping is correct.

#

And in your project you just want to compile your code to produce the application jar file.

spice hedge
strong ivyBOT
spice hedge
#

add ur own package name to it

#

Haven't tested it on mac

strange sky
#

got it working

#

is it possible to make a .sh (or whatever the linux .bat equavilient is) with installDist or something simular

spice hedge
#

it should be the other file that has no extensino

#

next to the bat file

strange sky
#

thanks