Downloading part of guava-libraries - java

Current version (14.0.1) of guava-libraries is 2 MB. It is not huge, it is not small neither. Especially when I want to use it in an exemplary project for my students and only need "Strings" part of it for parsing some input.
Are there any smaller parts of Guava available as JAR-s with compiled code, or I have to use all of it, or compile and prepare my own bundle (e.g. using ProGuard)?

According to Maven Repository there does not seem to be any smaller jar files that the Guava library is depending on.
So I would say no, there are no smaller portions of the Guava library that you can use. You will have to build your own jar files with only the classes you need.
So ProGuard seems to be the right solution for you.

Related

Is there any functional reason for including the version number in the name of a JAR file?

In Java, I often see JAR files named with the version number of the software (jsoup-1.11.2.jar), while others are not (freemarker.jar).
Is this just a best practice/convention, or is there some functional reason for it?
Simple answer: no, this is purely a convention.
Obviously, tooling that checks versions can do that easily when version numbers are hard-coded like this. But there is no generic (like jvm based) tool relying on it.
And beyond that - sometimes this scheme is even counter productive. In our self grown build setup we have to always remember to update the build scripts after replacing JAR files - because a new version changes the file name (because version part of the file name).
Having the version in the name of the file allows you to quickly determine which of the n files you have is the latest. Also if you have no way of determining what the version is from within the program it can be helpful.

Why do i need library file with -sources suffix?

I don't understand why there are often two files in libraries, one with -sources suffix.
Here's what i mean
The sources are useful if you want to step into the library when debugging. You don't need them, but they might save you if you can't understand why the library behaves in a certain way.
To add to the answer below, the -source archive is the actual source code, while the other file is the compiled version of it.

Does (or will) the JRE include a CLI parser

I normally use known CLI parsers (external libraries):
Apache Commons CLI http://commons.apache.org/cli/ (version 1.2)
Java Gems http://code.google.com/p/javagems/
JArgs http://jargs.sourceforge.net/
...
I haven't found one in the standard Java library, and I wonder if new versions of Java are providing an implementation so I can save a dependency. Does anyone know if there is something like that or a plan to include it in the future?
If when you say "native" you mean "java implementation included into JDK", the answer is "no". Obviously you can always create your own (more or less simple) parser based on arrays and string operations provided by java and JDK.
Concerning to choice among java CLI parsers I'd suggest you to use arg4j and can refer you to the following discussion: Java library for parsing command-line parameters?
One of the answers contains a very long list of libraries.
And the last note. I do not know why do you want to "save the dependencies". Use one of build tools that manage your dependencies (e.g. ivy, maven, gradle) and forget about such problems. if you want to distribute your program as a single jar, you can pack all your dependencies together with your application. Both maven and gradle can do this. If you want to achieve minimal jar size ... make your choice: what is more important for you - size or modularity. In most cases size is not an issue these days.
I don't think there is anything included in the JDK. Actually OpenJDK itself uses JOpt Simple (see comment at the bottom of the page).

Java(Android): Find unused classes

In my Android application, I am using lot of open source JAVA libraries as source. It makes the application very huge in size.
Number of classes coming around 6000+. I want to remove the unused classes from it. Any one have idea about how to do it. I find many tools, but that is for removing unused codes. Thanks in advance.
Use Proguard. It strips away unused classes and libraries. Link: http://developer.android.com/tools/help/proguard.html
EDIT:
The gc overhead limit exceeded is not because you are using proguard. Its because the memory allowed for eclipse to use is low. You can fix this by increasing the memory limit allowed (https://www.simplified.guide/eclipse/fix-gc-overhead-limit-exceeded). Do this, run proguard, and your app size will be minimal.
Well if you are using open source java libraries you should first find out what licences those libraries are distributed under. Some licences do not allow you to repackage distributables other licences will only allow you to repackage if you make the new software open source (that includes your code). http://opensource.org/licenses
So after you have checked the liceneces and or contacted the rights holders.
You could write a tool that follows the dependency tree from your classes through all of your third party code and produces a list of classes that are not in that tree. I imagine most IDE's are not going to do what you want because they will consider a library as either used or not.
proguard does this for java.
From what I'm seeing it's already part of the android stack - http://developer.android.com/tools/help/proguard.html .
Look at the link and try to find out why it isn't working for you (probably you aren't creating a Release build).
If it is working, and you still have a huge file, then you are probably using libraries that use a lot of files, and there's not much you can do about it.
Step 1
Generate usage.txt and mapping.txt with Proguard or R8
Add -printusage to your proguard.pro file Run
./gradlew app:minifyReleaseWithProguard or ./gradlew app:minifyReleaseWithR8
Step 2
Find class name records that is in usage.txt but not in mapping.txt, those are the unused classes that are removed by Proguard/ R8
It's not hard to write such algorithm but you can consider my approach using Java Set data structure
More details here
6000 classes ????? Well this is why people pay like 2000 for a compiler that removes unused code. If you put your code in eclipse it will place a yellow line under libraries, and variables that you are not using at all.
Hope this helps.

Is there a decent tool for comparing/diffing two Java packages?

I'm looking for a tool that will give me a high level view of which files are different between two fairly large Java packages. If I could then drill down into individual files then that would be good. I don't want to go file by file if possible.. any ideas?
thanks
Beyond compare (and other diff tools) can do directory compares too ...
If you're more interested in API differences than content differences, check out JDiff.
For example the Google Guava project uses it to show changes between releases. Here is the r06 release diff: http://guava-libraries.googlecode.com/svn/tags/release06/javadoc/jdiff/changes.html
WinMerge is an excellent Windows standalone diff tool and I use it for almost all of my source files. It can navigate through folder structures (in your case, your Java packages).
If you do use version control, it integrates very well with TortoiseSVN (and perhaps others in the Tortoise family).
You can use pkgdiff tool to compare java archives:
pkgdiff A.jar B.jar
See sample report for args4j.
See also japi-compliance-checker for analysis of API changes in your java archives.
I use Kompare on Linux. Just a diff GUI front end, that can diff directories recursively. I believe there are many others (I'm sure I've seen a list somewhere).
Eclipse works well. Just select the two different packages (hold the Ctrl key, click on a package, click again on the other package), right click on one of the selected packages, go to the 'Compare With...' submenu, select 'Compare With Each Other'.
I have used Araxis Merge to do this too. It is also helpful for doing code merges. It is not free (about 80 bucks I think) but well worth it.
I always use eclipses team synchronize (for included cvs; this requires one revision checked in and another one disk) works same way with subclipse plugin for subversion.
If you are on windows and don't have the checked in a version control system you could use winmerge
Last I checked kdiff3 worked both on *nix and windows.

Categories