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

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.

Related

Is it recommended to separate Scala and Java source files for a Maven project?

I've been working on a Maven project consisting entirely of Java, and lately started to mix Scala code into it.
I'm amazed by the great expressiveness Scala offers, the easy use of scala-maven-plugin, and especially the incredible interoperability between Java and Scala.
However, I hit one inconvenience; according to the Maven's convention, Java's source code goes into src/main/java, whereas Scala's into src/main/scala. I found it quite cumbersome because I have to frequently go back and forth Java and Scala source files and every time I have to traverse the deep hierarchy of package directories (I often close tabs to keep my editor from cluttered).
So the question is: Is it recommended to maintain separate directories src/main/java and src/main/scala? If so, why?
To add more background, I've been working on the web application framework Wicket, whose convention is to put the HTML files alongside with their corresponding Java files. If we keep the directories separated, naturally the HTML files are separated as well (I don't think putting Scala files and corresponding HTML files in different directories makes sense). And then it goes "why I can't find Foo.html? Oh, I was looking for the wrong directory."
The source files themselves are very easy to distinguish both by humans and by machines by inspecting their extensions. I configured pom.xml to handle both Java and Scala put together in src/main/java and it worked (compiles and runs). On the other hand, separating directories poses a risk of defining conflicting classes in Java and in Scala, a careless mistake.
Well, I don't want to name a directory java if it contained not only Java's but also Scala's. But this is the only point I can come up with for separating directories.
(Edit: I've come up with a workaround-interpretation; let us think java stands for Java Virtual Machine. In this way, having src/main/c doesn't contradict if we ever decided to use JNI because C doesn't run on JVM.)
Oh, and one more point; my project is not intended as an open-source project; development convenience is preferred than trying hard to follow conventions.
This question is inspired by this answer.
I'd say yes, re-use code as much as possible. Maybe in future you can use this Java piece somewhere else...
As you probably know, you can use Java in Scala projects but not Scala in Java projects. So in this specific example it will help you with (future?) Java projects. If you want to re-use a piece of your Java code you can do that in either Java projects as well as Scala projects.
So i.m.h.o. it doesn't stop at the src/main/... but you should really put them even in different components.
Btw, little side note: if I'm correct, Wicket allows you to put the html somewhere else too, even in a different project... I saw it being handy (only) once, where we had to create different frontend for different clients of us. The java code stayed the same, the wicket-id's as well, but the html changed everywhere. Though it did give us some problems as well using the Qwicky plugin, as it could not find the html files in our IDE anymore.

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.

Backing up Java?

I'm currently using Java and I'm looking for a program that saves a new version of what I'm doing each time I compile. I don't mind if it doesn't run, I can go in and edit the class name to make it match the .java name afterwards. As I'm a beginner, I keep getting caught by overextending myself and then breaking the project I'm working on irreparably. I'm just looking for a way to go back to a safe state.
I'm sure their are programs for this, but because I don't know the collective noun for them, finding one is next to impossible.
All help is much appreciated.
What you're looking for is revision control. This works independent of the language you're dealing with, since all the VCS is concerned with is the state of the software at a particular snapshot in time.
Some recommendations:
Subversion
Git
Mercurial
IntelliJ IDEA also comes with a built-in local revision system, which allows you to visit a particular file's history. It'd still be preferable to use either Git or Subversion.
There are also sites that you can host your project on to better preserve your project, such as Github or Google Code. Github uses...Git, but Google Code will allow you to use a few others, such as Subversion and Mercurial.
Use a Dropbox folder. If you use Eclipse, just put the entire folder in the Dropbox folder, and you are set to go with a backup-ed IDE.
Added bonus: access your project from anywhere.
You could also use GitHub, but then your source code will be open to the community unless you pay for one of their "plans".
Also, consider using Bitbucket, which isn't known as well, but is free. (Thanks to A--C for that alternative to GitHub)

How to make an eclipse plugin for text comparison of two files

I plan to make a text comparison plugin for eclipse which basically provides a visual aid for changes that are required in the file and allows the user to accept or reject them. It is very much in lines of subclipse for svn or any other code comparison tools. I already found a good source to perform the text comparison but I'm looking for some pointers regarding the implementation of the UI in eclipse.
Eclipse already supports this. Select two files, go to Compare With, choose 'Each other'. Does this work for you?
Buy a copy of "Eclipse Plugins" by Clayberg and Rubel.
For what it is worth ... Eclipse already includes text file comparison tools as standard.

Categories