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/
Related
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 am developing a GUI using swing that runs an executable. Currently the executable is being used via Runtime.getRuntime().exec().
I have both the executable and the source code. If I compile my GUI into a jar the executable will not be included into as it currently stands, correct?
I would like the whole thing to run as a single file, is it better then to use the source code or can I package it all as one jar when I'm done some how?
Though I'm writing all the code by hand I do have WindowBuilder for eclipse, I haven't really explored it thoroughly, is there anything in there that might help?
EDIT: Sorry, to clarify: The GUI I want to build uses an executable called src2srcml to take a source file (C, C++, Java) and convert it to an XML File. src2srcml is a separate executable I got from this website: http://www.sdml.info/projects/srcml/
I want to embed this executable into my GUI so that when I compile my GUI into a JAR it contains src2srcml inside it so that I don't need to send a client both my GUI and src2srcml separately.
If you include the executable within the Jar, the executable will not be runnable by the OS.
With that in mind, you have a number of choices...
You Could...
Design a build process that compiles and packages the jar file, takes that and the executable and copies it into an appropriate directory structure for distribution...possible even building installers...
This will mean that you can still access the executable at runtime by using a relative path
This does mean you will have at least two files you will need to distribute, but the over all process is relatively painless...
You Could...
Include the executable within the jar file. At runtime, you would need to extract the executable to the filesystem and execute it.
This means that you will have at least one file you will need to distribute, but it complicates the development process as you will need to find the resources (executable) at run time and extract it to some location before you can execute it
You Could...
Just build an installer for your application. Something like like izPack for example, or what ever installer you want to use.
This means that you can distribute a single file to the client, but when installed, it will unpack all the files into the installation location and you won't need to care...
I'm not sure if I understood your question, but if you want to export you application into jar file and you want it to include all dependecies just have a look at this SO question: How to create a jar with external libraries included in Eclipse?
I work daily on a large customized version of Android. Our work involves creating new APIs and testing them with our in-house test app. Currently, each person checks out the needed files to make API updates and then requests that I create a new version of the test app that works with their changes. The way I accomplish this, in part, is with a script that grabs their version of the OS files (the ones that declare the APIs) and generates a JAR of these files that is then thrown in the test app's "lib" directory so the test code can reference these new/changed APIs.
I've been able to automate so much of my workflow, but I can't find a way to automate the task of generating the jar from a few .java files that can't be compiled in isolation. I know how to create a jar and manually populate it, but I can't figure out how Eclipse is able to generate .class files for .java input source files that can't be compiled by themselves. The only way that I can currently compile these files is with a multi-hour full OS build, which I don't want to wait on. Also, our build servers don't spit out the individual .class files I would want to zip up in a JAR anyways.
So, does anyone know how to generate a JAR file with .class files compiled from .java src files that appear, by themselves, to be riddled with errors? I currently do this manually with Eclipse's "export project to JAR" ability, but it really irks me that it's the only "non-automate-able" step in my process so far.
I found this, which doesn't handle generation of the .class file(s) from a set of .java files that won't compile alone.
Thanks!
I'm building a website which will use files in order to render social graphs. These files are created by a backend in JAVA. This JAVA program consists of 4 classes and 4 libraries. I know that in order to run a JAVA program through PHP, I need to call it with the "exec" command but all the examples I saw have .jar executables and not .java files in the syntax. So, I'd like to ask two questions:
Is it possible to call just the .java main class from PHP without creating a .jar file? And if so, what's the syntax of the "exec" command?
If I have to create the .jar executable, would I just have to place it in the website folder and just call it? I mean, does the .jar file contain all the classes and libraries that the program needs? I don't talk about JAVA libraries, I have 4 specific libraries (MongoDB, Neo4j, GEXF parser and Lucene DB) which are not part of Java defaults. Thanks in advance and please forgive my syntax and spelling mistakes.
You have to at a minimum compile the .java files into .class files. It would be easier if they are in a jar file, but that is not required.
1)
a) java -cp /location/to/.class/files
b) java -jar /location/to/the.jar
2) the jar file does not have to be executable, though if that makes it easier, set the manifest up correctly and there you go.
When you say libraries, you mean other .jar files or native .dll or .so libraries? If the later, you have to have your library path setup to find them.
There is a PHP-Java bridge project on SourceForge. Also, you could expose your back end process by running it as a servlet, which is probably the proper way of doing it. If all else fails you can just "exec" it.
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.