I'm unsure if this would be more suitable for SuperUser, but I figured I'd went with StackOverflow.
Looking at an example of a game developed using Java, Minecraft, we see several resource files in the game's AppData/.minecraft folder. These are files such as .OGG sound files, basically files used to load content into the game, that weren't packed inside the minecraft.jar executable.
I'm working with Eclipse to develop Java applications, and I wonder, since you can import any kind of file into an Eclipse project, which would then be packed into an executable .jar upon export, what are the cons by packing a majority of the items, such as content, text files etc. into the project?
To decrease the size of the .jar?
I'd say, packing more things into a .jar would presume a bit more portability, but would result bit bigger size.
Perhaps my opinion wouldn't follow proper, and if so - why do Java developers want to, if they typically do, leave a lot of files beside the .JAR, for the .JAR to read? Especially static files (files that will not be modified or moved)?
Thank you!
Related
I have created an App using Java which treats excel files using Apache POI. The problem is that when I run the code from eclipse, it works fine, but when I made an executable jar for the app (Using eclipse export executable jar option), the jar is working fine but the results are different, even the size of the produced excel file is different.
I made many research, but I did not find a convenient solution.
Ah yes. I have had that same experience too a few years back.
When creating the runnable .jar in Eclipse, you can choose how .class files from libraries (such as Apache POI in this case) are handled:
Package required classes (.class files) into jar file
Package required libraries (.jar files) into jar file
Copy libraries into a sub-folder
Interestingly, with Apache POI, the three different ways of packing create HUGE differences:
In startup speed
In execution speed
In memory requirements (RAM)
In the resulting output files
I cannot recall which gave me the expected results.
So you have to try them out yourself. (Judging by how Eclipse starts Java projects, it should be #3, libs in subfolder, that gets you the same results). But: try the others anyhow; as I said, HUGE differences ahead.
TBH Apache POI is a 'good' example of how software should NOT be written.
It's awfully bloated and mega RAM hungry and has quite an interesting/odd behavior.
So I wrote my own lib for the newer .xls file format which is just a 100 times faster, smaller and more reliable. And does string caching and cell format operation optimization a lot better. So a 1000000 times better :-P
The upside is that the POI dev team knows the limitations and shortcomings of their project and offers multiple modes of processing files, to overcome said shortcomings. So, after all, kudos to them!
I am very new to Java (first-year student). I tried searching for similar questions but can't find anything that exactly meets my needs. I am trying to figure out how to create a JRE installer for Windows that includes additional files beyond the standard libraries. In particular, I am trying to use files from this source: http://jlog.org/rxtx-win.html. I want the RXTXSerial.dll file to go into the "bin" folder, and the rxtxcomm.jar file to go into the "lib\ext" folder.
Ideally, this would be used by a user who isn't good with computers at all, so that all they would have to do is run the JRE installer, and already have the necessary RXTX files needed to run an external application (that I unfortunately don't have any control over).
Take a look at install4j...
https://www.ej-technologies.com/products/install4j/overview.html
Not sure if this is exactly what you're looking for, but you should be able to control what JRE/libs are deployed with your application using this.
I have this, perhaps, easy problem, but I don't know how to handle this.
I have my Java program and it works pretty well when I call it via terminal (Java command).
The program uses 4 text files from the hard disk which can't be added as resources to the project.
How to do this right so I could build jar file only with main class and files from hard disk (first one is a config file and it has paths to other files so the program knows where they are)?
I'm using IntelliJ IDEA 14.1.4 on Arch Linux.
I did it based on this blog, but it's not working without txt files in src folder.
Also "jar cvf" command builds jar file, but it's not working outside my computer (for example on windows or OSX).
Can anyone help me?
I prefer step by step instruction so I would understand what is going on in here.
I recommend to build your application with Maven and create a Maven Assembly which contains your JAR file as well as the config.txt file.
I have been using apache ant to compile my java programs for quite a while, the problem now is that we have to learn to program in the .Net Framework.
I have been struggling with the building process of my csproj in ms build. The requirement we have was to create a build file of a program using only the VisualStudio Command Prompt and notepad++ to create the proj file.
Is there any task in msbuild where i can package my files similar to java jar? I searched within the MsBuild task reference but haven't found anything yet. Any help would be appreciated, thanks!
A JAR file allows Java runtimes to efficiently deploy a set of classes and their associated resources. The elements in a JAR file can be compressed, which, together with the ability to download an entire application in a single request, makes downloading a JAR file much more convenient than separately downloading the many uncompressed files which would form a single Java Application.
When you build a Dotnet application, you usually get a set of files (one .exe and multiple dlls as the simple scenario).
These files being "zipped into one common file" ... that concept does not exist in DotNet.
(except for Silverlight, but that's a different story...that's a "xap" file I believe).
Most people use a Msbuild Task to package their files together.
I use something like this:
MSBuild and creating ZIP files
to zip up my "binaries" on 1 zip file, and zip up my config files in a separate zip file.
That's a "poor man's" method...but it works.
So there is not a direct apples to apples comparison.
..........
That's the simple explanation.
When .dlls reside in the GAC, that's a different ball game.
EDIT::::::::
Here is an example of an extender library to zip files using MSBuild.
How do I zip a folder in MSBuild?
Here is 2 of the most common extension libraries
http://msbuildtasks.tigris.org/
and
http://msbuildextensionpack.codeplex.com/
Minecraft, a Java game, is free this weekend. The Windows version downloads as an exe file. I was curious what the EXE file is doing and where it's unpacking and running the actual game JAR from. So using a command, I found the command-line arguments to the running javaw.exe process; and oddly enough, it was launched with a classpath pointing to the executable! (meaning, the .exe file was acting as a jar). Indeed, after renaming Minecraft.exe to Minecraft.jar, I was able to open it and see the loader class files and such, as if it were a normal JAR file and not an EXE at all.
How is this possible? And how can I do it with my own JAR files?
This used previously to be very common - especially in the days of floppy disks where space was precious and it was tedious for the unzip program to be on a different disk than the zip file.
The reason why it can be done is because the zip-file inventory structure is located at the end of the zip-file, not the front, so a zip file can contain a large number of initial irrelevant bytes as long as the inventory structure does not point to them (and by extension jar-files too). A very frequent use for this has been to enclose a small unzip-only program which could then unpack the zip file.
One utility to prepend such a program is the unzipsfx. Here is a manual page for it:
http://linuxcommand.org/man_pages/unzipsfx1.html
It appears that Minecraft uses another prepended program which invokes Java on itself.
EDIT: Looked inside with an hex editor. Minecraft.exe is wrapped with Launch4j.
after renaming Minecraft.exe to Minecraft.jar, I was able to open it and see the loader class files and such
Some EXE files are in fact self-extracting ZIP files. JAR files are in turn normal ZIP files with a special file structure. I bet that you was just opening it using a ZIP tool after renaming it. Note that some ZIP tools will auto-integrate in Windows explorer (or the other way round) so that it happens seemingly transparently.
The ZIP (and by extension, JAR) file format is flexible in that it allows the archive to be embedded inside another file format. This is what makes self-extracting ZIP archives possible (some small code is embedded in areas that the ZIP file parameters ensure are ignored by unzip utilities). It has also been used for some particularly sneaky exploits as well.
My guess is that Minecraft similarly exploited the ability to make the archive a valid Windows executable and added code to launch the JVM with itself in the classpath.
See also: Wikipedia: Combining ZIP with other file formats
Launch4J does this. It's really pretty impressive.
If you want a quick solution without delving too much and using a wrapper, Jsmooth does its job well.