Skip to content

When using Winrun4J the main class is not found #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 5 tasks
commi opened this issue Feb 10, 2023 · 8 comments
Closed
2 of 5 tasks

When using Winrun4J the main class is not found #295

commi opened this issue Feb 10, 2023 · 8 comments
Labels
bug Something isn't working fixed Issue fixed and release pending

Comments

@commi
Copy link
Contributor

commi commented Feb 10, 2023

I'm submitting a…

  • bug report
  • feature request
  • other

Short description of the issue/suggestion:

When using winrun4j (or why) then the EXE does not start for me. Launch4J works.

What is the current behavior?

Lauch aborts with ClassNotFoundException.

When I edit the ini and add

classpath.2=libs\*.jar classpath.2=*.jar

it works .

Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement?

Output of the exe:

$ ./xpert-nba.exe
java.lang.ClassNotFoundException: de.intecsoft.mdkn.nba.App
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Unknown Source)
        at WinRun4JLauncher.main(WinRun4JLauncher.java:8)

Working $name.ini:

main.class=WinRun4JLauncher
log.level=error
ini.override=true
classpath.1=libs\*.jar
classpath.2=*.jar
vm.location=jre\bin\server\jvm.dll
working.directory=.
vmarg.1=-Djava.library.path=""

[ErrorMessages]
java.not.found=A suitable version of Java could not be found on your system. Please contact intecsoft.
java.failed=Java failed to startup successfully. Please contact intecsoft.

Please tell us about your environment:

  • JavaPackager version: 1.7.0
  • OS version: Windows 10 64bit
  • JDK version: 17
  • Build tool:
    • Maven
    • Gradle
@commi
Copy link
Contributor Author

commi commented Feb 10, 2023

Oh i just figured a can work around this by adding <classpath>*.jar</classpath> to the plugin config. That fixes it for me, but i'll leave it open because maybe there's and underlying bug.

@fvarrui
Copy link
Collaborator

fvarrui commented Feb 10, 2023

Hi @commi!
I wonder if you are using winConfig.wrapJar=false

@commi
Copy link
Contributor Author

commi commented Feb 10, 2023

I do,

But using winrun4j it says:

[WARNING] 'wrapJar' property ignored when building EXE with winrun4j

In any case we do use wrapJar=false, because we had errors reading resources from the JAR at runtime with Launch4j.

@commi
Copy link
Contributor Author

commi commented Feb 10, 2023

Hm winrun4j seems to ignore the <additionalResources> tag... i'll make an extra issue for that

edit: no it doesn't, the resources weren't coped because of some exception, prob nothing to do with JavaPackager

@fvarrui
Copy link
Collaborator

fvarrui commented Feb 15, 2023

Hi @commi!

I've managed to reproduce your issue and your patch works fine. I'm not sure why this stops working 🤷‍♂️.

You can use a customized template for the INI file as another workd around: just copy your modified version of the ini.vtl template in ${project.basedir}\assets\windows:

main.class=WinRun4JLauncher
log.level=error
ini.override=true
classpath.1=libs\*.jar
classpath.2=*.jar
#set ($classpathCounter=3)
#foreach ($cp in $info.classpaths)
classpath.${classpathCounter}=$!{cp}
#set ($classpathCounter=$classpathCounter+1)
#end
#if ($info.bundleJre)
vm.location=${info.jreDirectoryName}\\${info.winConfig.vmLocation}
#end
#if (!$info.bundleJre && $info.jreMinVersion)
vm.version.min=${info.jreMinVersion}
#end
#if ($info.useResourcesAsWorkingDir)
working.directory=.
#end
#set ($vmArgsCounter=1)
#foreach ($vmArg in $info.vmArgs)
vmarg.${vmArgsCounter}=$!{vmArg}
#set ($vmArgsCounter=$vmArgsCounter+1)
#end

[ErrorMessages]
java.not.found=A suitable version of Java could not be found on your system. Please contact ${info.organizationName}.
java.failed=Java failed to startup successfully. Please contact ${info.organizationName}.

What do you think about setting winrun4j as deprecated and leaving only why as alternative? Does why meets all your needs?

@commi
Copy link
Contributor Author

commi commented Feb 15, 2023

Thank you that's very flexible! I'll use it for now.

As for why, I got some error when i switched to it, but right now i cannot say if they might stem from elsewhere in our build chain. winrun4j works great so we'll keep it for now. But I'll update if we can make why work.

@fvarrui fvarrui added the bug Something isn't working label Feb 15, 2023
@fvarrui
Copy link
Collaborator

fvarrui commented May 4, 2023

Hi @commi!
Fixed in 1.7.2-SNAPSHOT.

I've just added this line to ini.vtl:

classpath.2=${info.jarFile.name}.jar

Instead of loading all the JARS in your app folder, just load your app's runnable JAR.
I tried and it seems to be working fine.

I hope this fix this issue!

@fvarrui fvarrui closed this as completed May 4, 2023
@fvarrui fvarrui reopened this May 4, 2023
@fvarrui fvarrui added the fixed Issue fixed and release pending label May 4, 2023
@fvarrui
Copy link
Collaborator

fvarrui commented May 7, 2023

Close this issue due this fix was released in JP 1.7.2.

@fvarrui fvarrui closed this as completed May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Issue fixed and release pending
Projects
None yet
Development

No branches or pull requests

2 participants