Exe created by Exe4j with external libs dependation - exe4j

We are trying to wrap our jar file with exe4j to exe file. Our jar depends on several jar libraries stored in libs folder.
We don't want to distribute jar file, only exe and jar libraries in libs folder.
For execution of application we are using own JRE.
Here is the file structure of application:
/java
/libs
application.exe
In the project type, we are using "Jar in exe mode" option.
Exe is generated but its execution failed. In errors.log I can see, that
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
If I add slf4j.jar to classpath, generated exe is bigger and there is another NoClassDefFoundError in error.log file.
If I try "Regular mode" and specify folder with external libs - application is working well. But to specify folder is not accessible for "Jar in exe mode".
Is there any way, to have exe which wraps jar file, and uses jar libraries which are stored in external libs folder, without manual specify them and pack them to the exe?

We don't want to distribute jar file, only exe and jar libraries in libs folder.
The JAR file in the generated executable is not protected in any way, because it will be extracted to the %TEMP% directory when the executable is started. This is why you can just use the regular mode and put the JAR file in the lib directory.
To protect the JAR file, use an obfuscator like proguard.

Related

.NET 5 excludes some libraries from single file publication

I have a little problem with single file executable publish with .NET 5.
Infact, it does not include all libraries in the executable file, and produces multiple files.
In my example I'm using a library for SQLite (Microsoft.Data.Sqlite) and, after compilation, e_sqlite3.dll is not included.
Instead, in the output folder, it produces two files (excluding the pdb file):
> e_sqlite3.dll
> WpfApp1.exe
By reading documentation
Single-file doesn't bundle native libraries by default. On Linux, we prelink the runtime into the bundle and only application native libraries are deployed to the same directory as the single-file app. On Windows, we prelink only the hosting code and both the runtime and application native libraries are deployed to the same directory as the single-file app. This is to ensure a good debugging experience, which requires native files to be excluded from the single file. There is an option to set a flag, IncludeNativeLibrariesForSelfExtract, to include native libraries in the single file bundle, but these files will be extracted to a temporary directory in the client machine when the single file application is run.
So (in my case e_sqlite3.dll) native libraries are not included by default to ensure a good debugging experience.
If you want to include them anyway in the application executable, you can simply add this line to the project (.csproj) file.
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
Example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<StartupObject>WpfApp1.App</StartupObject>
<Description>WpfApp1</Description>
</PropertyGroup>
...
</Project>

How to ship .dll files with the .exe file

I have an application that depends on some .dll files.
I know if I just make them in the same folder as the .exe file, it would work, but I don't want to leave 30 .dll files with my .exe file. Is there a way I can put them in a folder with my .exe file ?
Or even better, is it possible to compile them and link them with the .exe file to have a standalone file? And no I don't have the static version of these dynamic libraries.
(p.s. the application is written with c, compiled with gcc, mingw win64, and the .dll are from gtk3 libs)
Thank you for reading my question
You have a number of options.
A) get hold of the library files, .lib on windows and statically link with these libraries.
B) It is a bit of a hack but you can attach resources into a Windows executable. This is usually used for strings, icons, that sort of thing, but you could even attach in a binary file. But if you do this you would probably need to generate the dll binaries at program startup and save to eg same folder as your executable. So no point in doing this really, simply distribute in the same folder as your exe. What is the problem doing that? (lookup LoadResource, FindResource, MAKEINTRESOURCE, etc)
C) If you don't want to put the dlls is the same path as your exe you will need to store them in a folder in your system's path env variable. Eg you could copy them to C:\Windows - but due to security that will be harder. You could create your own dll_path and add this path to the env variable as part of the installation of your program.
D) One other variation on C) is that you copy to for example a subdirectory of you exe location, called eg dll_files. Then you use a startup script to launch your program like this:
#echo off
set PATH=%PATH%;<path to dll files>
myprogram.exe
Let's make is simple
download winrar from www.rarlab.com/download.htm A) create standalone winrar executable pack your file in archive and execute your main program.
no idea how to create standalone installer guide for you
http://www.groovypost.com/howto/howto/how-to-make-your-own-offline-installers-using-winrar/

Executable built with VS2010 does not find DLLs in System32

I recently built a project on VisualStudio. I got an executable in the bin folder and I put all the dependencies x64 DLL in C:\Windows\System32 and all the x32 DLL in C:\Windows\SysWOW64
When I execute my executable, I get an error message This program can't start because foo.dll is missing from your computer.
I tried to get the dependencies with ldd.exe on Cygwin, but I don't see any references to foo.dll. I also tried to execute from PowerShell Start-Process -PassThru sample.exe, but I still get the same error message.
Where does Windows executables look for DLLs?
I've read that a Windows executable will look for its dependencies in a certain order:
In the local folder
In System32
In the %PATH%
I also read that I may need to use regsvr32.exe to register my DLL if it is located into System32.
What is the actual reality of this story?
Alternatively, you can simply add the DLL files to the bin folder as well.

Creating an EXE from Python Script, how to bundle other exes

I am creating an EXE file from a python script using pyinstaller and I need to include the Selenium Chrome and IE executables with this exe. How can I bundle those so when someone installs my exe it also includes both of those?

Running Executable

I have an executable that is generated using VC++. The VC++ project includes some of the dlls and when I tried double clicking the exe, it is asking for the path of the dll's.
Is it possible to place the generic dll's into a common folder, open the exe file using the batch file and provide the reference path of the dll's??
See this link for information on DLL search order on Windows.
Quick and incomplete summary:
The directory where the executable module for the current process is located.
The current directory.
The Windows system directory.
The Windows directory.
The directories listed in the PATH environment variable.
Note: The LIBPATH environment variable is not used.
EDIT
To address the comment about having the external DLLs copied locally:
After adding the files to your project, right-click one, select Properties. In the General section, change Item Type to Custom Build Tool. Now in the new section Custom Build Tool, change the Command Line to copy that particular file to the output directory.
You can also do all the necessary file copying in the Pre/Post-build steps of the project.

Resources