So figure we have a Jar file with our Java application, and it has inside of it the Jar files for the libraries it depends of, a the jdbc or any other third party jar.
How do you proceed to obfuscate it with free software? I mean, obfuscate your code and leave the Jars untouched.
I tried with Proguard, to no avail. Even the author told me at the sourceforge forums it wasn't possible.
But you can do it manually with an ugly hack involving the renaming of the jar to zip and mangling with the inner data, so, why wouldn't a software be able to do it?
You can create a single jar from multiple jars using Jar Jar Links.
Then you process the result with ProGuard.
Presumably, you have some sort of build script in place to compile your source, package it with the other jars (One-Jar/Fat Jar/etc.), and build your jar.
You should be able to insert the obfuscation task between the compilation and packaging.
If your obfuscation tool of choice will only take a jar input, you should be able to compile, jar, and obfuscate your code independently. After that, have your script unjar the obfuscated file and do your packaging.
Don't waste your time. Anyone can decompile your obfuscated code, the only thing you're going to do is frustrate your legitimate users who want to debug problems with your software.
Obfuscation is a technical solution (and a poor one at that) to a legal problem.
Related
What is the equivalent project file for a Java project? For example, a C# project file is denoted by the delimiter of .csproj. So what would it be for a Java project? Is it dependent on what IDE I am using for Java?
I did some search online about this and it seems to me that the answer to this question is dependent on the IDE. From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated. I do not want to be steered in the wrong direction on this and so I want to first ask around for guidance.
You're probably looking for the build file, not the IDE project definition.
Is it dependent on what IDE I am using for Java?
Yes. IntelliJ has .iml files, and Eclipse has .project (that's not a file ending - that's the file), as well as .classpath, .factorypath, and more. But, many of these are effectively generated or just refer to the build file. In C that tends to be called Makefile, in the Java ecosystem, Gradle and Maven are the 2 most popular build tools; they have build.gradle and pom.xml respectively. These would be more useful as basis for knowing how a project is 'put together', so to speak.
From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated.
That's very basic and should rarely work except for the simplest projects. For example, most Java projects have source files, test files (also source files but they are not part of the distribution), and resource files (non-Java files that are also needed for the app; think about the images for the icon on a button), as well as a ton of dependencies (third party libraries used by the Java app).
Given that folks like many IDEs, the IDE 'config file' is not what you are looking for, and many projects don't even check these into source control (and probably shouldn't). Together with the source, you have a build file. This build file knows how to download dependencies, compile every artifact (there doesn't have to be one; maybe there's the test code to the built, the main app, a plugin for some other tool, and an installer. Build tools can handle all that), run the tests and report on them, possibly even tell you about code coverage, and they usually can run the app, but more generally, you just want to tell the build tool to build a distributable for each relevant artifact.
Those build files are what you're looking for. With those you can build your project, or point an IDE at them and then you can edit the project with all the dependencies and classpath linkages all worked out for you.
Is there a technical reason for not having the source java files in the jar file? I came across a service jar that had both the class jars and the source java files in the same jar. Typical third-party libraries will bundle these different types of files into separate jars. The binary is necessary for execution and the src.jar file is useful to debug using the exact code that the class files were built with.
To me the reasoning is: it slows down server startup because the additional files need to be decompressed and perhaps indexed. Are there any other reasons I can use to advocate for abandoning this one-off build process?
Please do not respond that jar files are essentially zip files and anything goes, I am looking for technical reasons during runtime to avoid this situation. BTW the services using these JARs have been working for a long time, so it is not manifesting any actual perceived defects.
It shouldn't cause any problems to have source files in the JAR with the binary class files. The main reason to keep them separate is to avoid making JARs bigger than necessary for runtime deployment. As far as I know, the convention of distributing a -sources JAR file for open source libraries originated with Maven, which will produce artifacts in this way by default.
I've recently come with the need to create for a Java project a build.xml file in which is meant to be run using the terminal.
The issue is that until now we've used Eclipse as the utility to run the build.xml while depending on Eclipse UI to let the Ant package manager to create our jars, but not putting the external jars in each jar we create.
That way, the memory in which the jar libraries take(~40MB) isn't replicated to each Jar we make.
I'm pretty a beginner in Ant so what I'm trying to do is create a build.xml in which take a folder of Jar libraries, and for the project which is a Jar library itself, create the Jar while knowing the libraries but not include them in the end Jar.
I alternatively tried understanding how eclipse teels the build.xml for ant but the classpath of the project, how to access the jars and other configurations, so if there's a possibility for that then it will be much better.
If possible, it would be great to help with that.
I've tried of course seeing other questions on Stackoverflow but didn't saw something similar to this.
If there's one of course I'll be happy to see it :)
Thanks heads up! :)
When writing my projects, I use a number of apis and libraries. The projects compile - I have added the .jars to my classpath - however, the relevant .class files are not added to the final jar. Is there a way to force this? I'm not using an IDE like Eclipse (and would honestly prefer not to).
No, the classes aren't meant to be added to your jar file. Instead, the idea is that you supply the 3rd party jar files alongside your own jar file. If you really need to only have one jar file, you'd need to merge all the jar files together - but I'd strongly recommend that you don't do this unless it's absolutely vital. (You'll need to work out how to merge the manifests etc).
I have multiple JAR files, which I have to add to classpath in Eclipse.
Is it possible to combine 30 files in one file and include that file?
You can, but I don't think it would necessarily be a good idea to do so. Three possible reasons, and no doubt there are more:
It makes it harder to see where any one constituent file comes from.
It makes it harder to replace just one library
If there are files which are contained in multiple jar files, which should "win"? For example, all the jar files will have their own manifest... you may be able to merge them all, but not necessarily... and for other files there may well simply not be a sensible way of merging them.
My vote is to keep the jar files separate.
Your may want to have a look at jarjar.
If you use an ant task you can also go for zipgroupfileset:
<zip destfile="jarlibrary.jar">
<zipgroupfileset dir="lib" includes="*.jar"/>
</zip>
There are a number of existing tools for this:
Uberjar
Megajar
Onejar
This question seems probable duplicate. Please try to find answer from similar article in this forum
Clean way to combine multiple jars
The jarjar project is what you need.
There is another thread here that explains how to package jars for releases, including using Ant, jarjar and eclipse plugins.
First, you can. JAR is just a ZIP file. You can extract all stuff into one directory, then create zip file (even manually using WinZip or similar tool), call the result *.jar (if you wish) and add it into the classpath.
The only problem that will probably happen is if several jar files contain resources with the same name (and path). for example, manfest.mf, or other descriptors. In most cases it will not cause any problem but sometimes if application code uses these resources you can have trouble.
There are some automatic tools that do this. Take a look on JarJar.
BUT the more important question: why do you want to do this? If you do not use maven put all library jars to one directory named lib under your project. Then add all these jars to your classpath in eclipse using 2-3 clicks. That's it.
if you are using maven, include all your direct dependences into your pom.xml, compile the project, then say mvn eclipse:eclipse. This will create .classspath and .project for you. Now just use it.
Jar files are just ZIP files, so you can try to unzip all jars, put all files together and then ZIP them again.