orphan-oss / launch4j-maven-plugin

A Maven plugin which wraps Launch4j
Other
364 stars 71 forks source link

dontWrapJar causes 'Could not find or load main class' #388

Open dhakehurst opened 2 months ago

dhakehurst commented 2 months ago

Hi, great plugin, however I'm having some issues. I wrap everything into a FAT jar, which I can execute fine. I would like to create a .exe that executes the jar.

I want to end up with a directory structure of

app
 |--app.exe
 |--lib
      |-- app.jar

so I have created a configuration that looks like:

 <configuration>
      <headerType>console</headerType>
      <outfile>target/app.exe</outfile>
      <jar>lib/${project.artifactId}-${project.version}-FAT.jar</jar>
      <dontWrapJar>true</dontWrapJar>
      <classPath>
          <mainClass>${main-class}</mainClass>
          <addDependencies>false</addDependencies>
          <jarLocation>lib/</jarLocation>
      </classPath>
 </configuration>

I construct my desired directory structure using the assembly plugin. The resulting directory structure is correct, however

If I run app.exe from the directory 'app' that the exe sits in, it works fine, but if I run it from some other directory it gives the error

Error: Could not find or load main class com.itemis.fit.cli.MainCli
Caused by: java.lang.ClassNotFoundException: ....

How do I ensure that the location is relative to the .exe location, not the directory I run the exe from ?

dhakehurst commented 2 months ago

I have discoved if I set <chdir>.</chdir> then the exe can find the jar and it works.

Is this the correct thing to do?

I would prefer/expect the pwd to remain as the directory the user runs the exe from!

akuhtz commented 2 months ago

Hello,

Have you tried to use in classpath?

... .

Regards, Andreas

Am Mo., 22. Juli 2024 um 17:36 Uhr schrieb Dr. David H. Akehurst < @.***>:

I have discoved if I set . then the exe can find the jar and it works.

Is this the correct thing to do?

I would prefer/expect the pwd to remain as the directory the user runs the exe from!

— Reply to this email directly, view it on GitHub https://github.com/orphan-oss/launch4j-maven-plugin/issues/388#issuecomment-2243256198, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALJBXWXEENCU2HOHYXJ5W3ZNURH3AVCNFSM6AAAAABLIQID2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBTGI2TMMJZHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lukaszlenart commented 2 months ago

from top of my head could you try to use <jarLocation>./lib/</jarLocation>

lukaszlenart commented 2 months ago

\<chdir> Optional. Change current directory to an arbitrary path relative to the executable. If you omit this property or leave it blank it will have no effect. Setting it to . will change the current dir to the same directory as the executable. .. will change it to the parent directory, and so on.