How to reduce the size of an exe made from a jar developed in netbeans? - jar

I developed a tool in netbeans and I wanted to make its exe file so I used Excelsior JET.
But the size of the exe goes to 17MB, even though my jar has a size in KBs only.
What should I do to make the size of exe lesser?

You won't be able to bring the size down to KBs with any tool, because your program would still require the services provided by the JVM - threading, garbage collection, JNI, and so on - and, more importantly, the Java standard library. That is a lot of classes, and even the simplest Java program would load hundreds of them (just run "Hello, World!" using the conventional java launcher with -verbose:class).
Specifically with Excelsior JET, you may have an option to use Compact Profiles, a pre-Jigsaw feature introduced in Java SE 8:
https://www.excelsiorjet.com/solutions/java-download-size
But you would need at least the Professional Edition for that.
DISCLAIMER: I work for Excelsior.

Related

How to reduce size of winforms executable in .Net6?

I am very new to .Net6 and .Net Core in general. I understand that it is possible to publish a single file executable but I was a bit surprised to see that the executable is over 180MB even though the application is relatively small.
The application is targeted to Windows x64 only and uses Windows Forms. It has a handful of Forms and uses a JSON library and a CLI library.
There are a number of dependencies which were more-or-less added automatically but I don't know if they are all strictly necessary (e.g the ASPNetCore item)
Bearing in mind that I am only targeting Windows and the featureset used is limited, what are the actions I can take to reduce the size of the executable?
Update
I found https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained which seems to indicate that 'trimming' of WinForms apps is not (yet) possible.
If you already did not, you may switch deployment mode to Framework-dependent from self-contained in publish profile settings, this will exclude .net runtime and will reduce file size dramatically.
However, excluding .net runtime, diverts from its purpose being single file, as you need to install correct runtime to use application. In my opinion, it is worth to keep single exe file with runtime included.
Use This code into your application.
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>

How can I convert a JAR file to an EXE file?

I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:
How can I convert the JAR file to an EXE file?
How can I encrypt the JAR file's contents? The jar file could be extracted with WinRAR and the classes could be decompiled with any Java decompiler.
How can I create an installer? My clients doesn't have any JVM and I don't want to ship JDK or JRE along, because they have big size.
See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.
You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.
If you have an exe there are installers enough.
JSmooth is a application which will wrap your Jar in an exe
it also allows you to check if the correct version of JRE is available on the system you're deploying to
http://jsmooth.sourceforge.net/
As for 1): I guess you can not. There may be tools out there, but you cannot do that with standard tools shipped with JDK, as it would destroy platform independance. (See other answers providing links to such 3rd party tools)
As for 3): Use InnoSetup to create the installer. Include JRE within setup and let InnoSetup install it on the fly.
You can't prevent decompilation. The best you can do is make it harder or more time-consuming to do so. As an answer to your question though, I believe you can use gcj to compile Java into EXEs.
May be Excelsior JET will satisfy your needs.) IMHO very mature product.
1) I have recently tried the program jarToExe and like it.
Some features are:
free basic version or very cheap ($30) for 'enterprise'
ability to have windows task manager list your app's name instead of the default java.exe
extra obfuscation
runtime check that java is installed
2) You can make it harder to reverse engineer using proguard or other obfuscator
3) nsis is a very powerful, free scripting language to create windows installers. Good documentation on the site wiki and support on stack overflow as well.
Launch4j worked for me while some tools hadn't been working. It also have a good guide here.
Hope this help!
We use a 7zip SFX install launcher. This is an open source simple tool. It will package your jar, a version of jre so it's not mandatory for the installing systems to have jre installed and a self extracting version of 7zip. Here is a tutorial which explains how to bundle and GitHub link
The project is not maintained but works perfectly(tested until Java 1.8)
1) To create the exe, you can use Launch4j
2) As I have seen, you cannot encrypt the jar contents. I'm not sure though.
3) To create the installer you can use the exe you just created and use InnoSetup to create the files. You have to embed the jre inside the installer and also any other libraries and extra files that may need in the runtime. When embedding the jre, the setup gets large and if you want to avoid that, you can ask the clients to install java in the machines. That way, you wont need to ship with the jre.

Deploying QT app on OS X and linux

Whats the best way to deploy a QT app? I've read the documentation hosted at trolltech but is it better to link with a static library or the dynamic libraries and have the user install the framework? I don't really want anyone using my app to have to download a 160mb framework just to run a simple gui frontend.
On OS X it's a good way to do a dynamic build and post-process the resulting ".app" with the macdeployqt tool which comes with Qt starting with 4.5.
This will copy the Qt frameworks used by your application into the application bundle, which results in a larger package than building a static version of your application.
Here is what you can do to make sure you get the smallest file size possibly in a dynamic build:
First off, make sure you only include the stuff you need (in the project.pro file's QT += core gui network xml lines).
Open the application bundle and remove any unneeded "Qt Plugins" from the bundle. macdeployqt automatically compies all the Qt plugins in there, which can be kind of bulky.
Make sure you are building your application in release mode. Otherwise your application might be linked against the debug libraries of the Qt4 framework, and they are really big (for instance, well over 90 MB for the debug library vs. 16 MB of a release variant without debugging symbols). This might be what happened in your case.
If you have a large application binary, you can use UPX to compress your executable file by 40-50%.
Other than that, you should use compressed disk images to deploy your application.
One of my projects uses QtGui, QtNetwork, QtCore and QtXml and the resulting bundle is about 16 MB in size.
Hope that helps.
Unfortunately you will have to include the Qt libraries you need into your own bundle, as you cannot expect your users to have Qt installed on Mac (whereas on Linux packaging systems allow you to require at least a given version of Qt.
There is a nice tool to help you with that, which is called macdeployqt. You just need to invoke it on your bundle application and it will pack the required libraries, changing the linkage of your binary to refer to them. Without it, making bundles for Mac is a real pain (it still is, but considerably less though).
http://doc.trolltech.com/4.6/deployment-mac.html#the-mac-deployment-tool
Afterwards, you can make a .dmg image as you would do with any other app. There is an option in macdeployqt that builds a basic one.
On Linux, it's better to rely on the OS's copy of Qt, as it's almost certainly installed - for OS X, almost all apps use a statically compiled library.

dos command flex core

can i execute some dos like command from flex just like
attrib c:\a.txt -h.
function available in c exec(), in java Runtime.getRuntime().exec().
but in flex is there any available?
I think the closest you're going to come to achieving this is by using fscommand(), which has quite a few limitations.
Remember that Flex applications run in the Flash player (usually within a browser) and thus don't typically have access to shell commands of the host filesystem.
Two of the most requested features for
Adobe AIR have been the ability to
launch native executables from an AIR
application, and the ability to
integrate native libraries into an AIR
application. Unfortunately, neither
feature will be included in Adobe AIR
1.0.
But there is a workaround. It's a bit complicated, yet elegant, and should solve your problem. It relies on CommandProxy, a kit for proxying calls between applications and the operating system. You will find here a detailed article on how to implement this solution
If you want to run batch files using flex..then do the following
var file:File =new File(path to batch file)
//do not give the .bat extension only file name is reqiured.
file.openWithDefaultApplication();
// the batch file will open and run the dos commands you have written

Any advice for speeding up the compile time in Flex Builder 3?

I run Flex Builder 3 on a mac and as my project grows - the compile time gets longer and longer and longer. I am using some SWC's and there is a fair amount of code but it shouldn't take minutes to build and crash daily should it?
First of all, comments on some of the response:
There is no need to explicitly specify -incremental in Flex Builder because it uses incremental compilation by default.
-keep-generated-actionscript is a performance killer because it instructs the compiler to write out AS3 codes generated for MXML components in the middle of the compilation. File I/O in the middle of a compilation means unnecessary pauses and low CPU utilizations.
-optimize slows down linking because it instructs the linker to produce smaller SWFs. Note that -optimize=true|false doesn't have any effect on building SWCs because SWCs are libraries and have to be unoptimized.
I rarely mess with JVM settings because JVM knows its jobs well and tunes itself quite well at runtime. Most people make matter worse by setting various GC tuning parameters. That said, there are 3 settings most people understand and set correctly for their usage:
-Xmx (max heap size)
-server or -client (HotSpot Server or Client VM)
-XX:+UseSerialGC or -XX:+UseParallelGC (or other non-serial GC)
-server consistently outperforms -client by about 30% when running the Flex compiler.
-XX:+UseParallelGC turns on the parallel garbage collector. ideal for multicore computer and when the computer still has CPU cycles to spare.
You may also want to check out HellFire Compiler Daemon (http://bytecode-workshop.com/). It uses multiple processor cores to compile multiple Flex applications at the same time. You can also run the compiler on a second machine via sockets (assuming that your second machine has faster CPUs and more memory).
In my opinion, use more modules than libraries and use HFCD.
Hope this helps.
-Clement
There's no need to use mxmlc on the command line just to be able to add compiler flags. Right click your project in the Flex Navigator, select Properties and then Flex Compiler in the dialog that appears. There you can add any extra compiler flags.
Not sure that there's very much to do though, more code means more compile time, that's just the way it is. If you're not doing a release build (or whatever it's called in Flex Builder) it's unlikely that your compiler settings include optimize to begin with. Better choices to try would be -incremental (which only recompiles the parts that have changed) and -keep-generated-actionscript (which stops the compiler from deleting the ActionScript files it has generated from your application's MXML files).
I very much prefer using mxmlc on the command line (by way of Ant) compared to Flex Builder. Although I don't think that the latter compiles any slower, it feels more sluggish in every way. Using Ant also makes it possible to do more than just compilation when building, and conditional compilation (only compile a SWF or SWC if the source code has actually changed). Check out a blog post of mine for more info on that.
What you could try is the Flex Compiler Shell, another command line tool that can speed things up. Basically it tries to keep as much as possible in memory between builds, so no need to wait for things like the JVM starting up (the Flex compiler is a Java application). On the other hand this is sort of what Flex Builder does anyway.
In addition to the suggestions already mentioned, close any projects that you have open that you are not using.
Rich click on the Project in the Navigator view and select "Close Unrelated Projects".
Depending on how many projects you have open, this can lead to a significant improvements in compile time, as well as all around performance.
mike chambers
mesh#adobe.com
Slow compile time is most often caused by having large numbers of embedded resources ([Embed] or #Embed).
Option 2 on this article might help you: [http://www.rogue-development.com/blog2/2007/11/slow-flex-builder-compile-and-refresh-solution-modules/]
I created RAM Disk with workspace and it gives up to 10% of better compilation time. Not much, but something.
You want at least 4 gigs on your computer if possible, and make sure to override the default memory settings that eclipse/flexbuilder gives to the application.
If you're not sure how to do this, you can find the flexbuilder app in /Applications, right click and choose "Show Package Contents". Then go into the contents file and edit the eclipse.ini file. Edit that file have memory settings of at least:
-vmargs -Xms768m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=128m
It's also worthwhile to go into the eclipse/flexbuilder preferences and to check the "Show heap status" box under Windows->Preferences->General (This is in eclipse with the FB plugin, I'm assuming it's also there for standalone FB).
This shows the current memory in the lower right of the window and has a little trash icon so you can force garbage collection.
I'd also suggest turning off automatic building of the project when your files change (you can force a build with cmd-B).
We had a huge project with quite a few modules files and performance in FlexBuilder 3 was decent with these steps.
Go to Project->Properties->Flex Applications. All of the applications listed are compiled each time (even though you have a default set). If you remove everything but the default (don't worry, it won't delete the actual files), it only compiles the default app. This resulted in a significant speed up for me. If you change your default app, it ADDs it to the Flex Applications list - adding to your compile time. You will need to maintain this list to get the quickest compile.
I always disable "automatic compile" for Flex. It compiles too much, takes too long, and so interrupts my work.
If you have many different project files and all of those needs to be recompiled, but you also have other projects open and don't want to close them always you're doing a build, you can also use Eclipse Working Sets.
Unfortunately, the default Flex Navigator does not support working sets. But you can open the Package Explorer with Window / Show View / .... Click on the little white downward arrow to the topright and select Top Level Elements: Working Sets. You can then add Working Sets (aka groups of projects). Each project needs to be in at least one working set ("Other Projects" being the default), but can be in several.
Now with Project / Build Working Set / ... you can instruct Eclipse to build all the projects in this working set, but none of the others. This is especially useful if you suspect your project references to be sometimes broken - otherwise building the 'topmost' project should trigger subsequent builds automatically.
As Clement said, use the HellFire Compiler Daemon. If you have multiple modules and more CPU cores on your machine it can compile them in parallel. Another option is to use IntelliJ (the commercial version) which offers the same feature.
The SDK 4.x.x introduced silly bug (see Adobe bugsystem, issue FB-27440), which causes projects with SVN or CVS meta data compile much slower than with SDK 3.x.x. On how it can be fixed, see here.
You may want to explore the command-line compiler found in the Flex SDK, mxmlc. As I recall, Flex Builder 3 seems to hide all the compiler details, but perhaps there are arguments you can append that will help you speed up the compilation.
For example, you may want to set optimize=false which will skip the step of optimizing the bytecode (perhaps reducing compilation time)? This of course comes at the price of performance and file size of the actual application.
More documentation on mxmlc can be found at: http://livedocs.adobe.com/flex/3/html/compilers_13.html.
Good luck!
I don't use Flex Builder, but I use the Flex SDK compiler everyday and I was wasting tons of time waiting for the MXMLC compiler to do its job until I found Flex Compiler SHell:
http://blog.zarate.tv/2008/12/07/theres-something-called-flex-compiler-shell/
Although in theory Flex Builder already uses this optimizations, might be worth checking.
You can use WORKING SETS to compile just a set of your components that are part of the application that you are changing and not the whole project
http://livedocs.adobe.com/flex/3/html/help.html?content=build_6.html
Usually the first build takes the longest, and then it's pretty quick after that. That's using Vista x64 w/ core 2 duo.
Otherwise, I am nearly certain a Intel Core i7 Extreme Edition 965 3.2GHz upgrade processor would speed your Flex building up nicely .. :) :) :)

Resources