Corrupted jar files - jar

How to identify the corrupted jar files in my classpath using jar commands.
Will -xvf help in sorting out corrupted jars?
Please help.

I think you would need to look at each jar file individually and allow the jar command to tell when an archive is corrupt. You can use the list command for this:
$ jar tf <jarfile>
Alternatively I guess you could just run java itself, with your desired classpath, and hope that is declares which jar files are corrupt.

Related

How to convert jar file to eclipse project

I want to convert my jar file to eclipse project, so that i can make changes in the existing code. Can anyone help me with this. I tried extracting jar using jar xf myjar.jar command through command prompt but it gave me only .class files and i want to generate .java files of my project through it.

How to update a JAR file with a modfied Java file

I have one JAR named as abc.jar with 15 class files. In JAR file I need to modify xyz.class, so I decompiled to xyz.java and modified it.
How can I update that JAR with the modified Java file? While trying to create (compile) the JAR file I am getting errors.
You can add your newly compiled class to the jar and overwrite the old one, here is how to add xyz.class and xyz.java to the jar :
jar uf abc.jar xyz.class xyz.java
See here for more about updating a jar file.
Or simply you can use any archiving tool, like winrar to open and add files to the jar.
Compile the xyz.java and replace the xyz.class file directly in jar without building the jar again, if the single class has been modified.

jar file is not including in build.xml

What could be the reasons for a jar file not to include in build, even everything was given correctly. I tried the same syntax with other jar files which worked. But when i am using it for protocol buffers jar file, it is not being included.
Thanks !

jar -uf is deleting the file inside the jar

I am using jar -uf to update my MANIFEST.MF file like this:
a. jar xf jarfile.jar META-INF\MANIFEST.MF
b. edit the file
c. jar uf jarfile.jar META-INF\MANIFEST.MF
But the 'uf' command is removing MANIFEST.MF from within my jar.
What is the right way to change a file inside a jar (windows 7, jdk 1.6)?
You can always use winrar (or any equivalent) to open the jar, and drag/drop the files. worked for me.
For updating the manifest file the jar command provides different option -
jar umf manifest jar-file
The m option indicates that you want to update the JAR file's manifest.
manifest is the manifest whose contents you want to merge into the manifest of the existing JAR file.
examples # http://java.sun.com/developer/Books/javaprogramming/JAR/basics/update.html
There is a special option (m) for the manifest file: http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/jar.html
Could you try with
jar um jarfile.jar META-INF/MANIFEST.MF

How do I find the packages defined in a jar?

I have a bunch of JAR files (from a maven2 project) and maven reports some package could not be found (org.openanzo.client.jena to be exact). I want to dig into the JAR files downloaded as the result of maven dependency resolution and find what packages are thus available from these JAR files. Insights?
UPDATE: Apparently, the only good solution to inspect insides of a jar file is the "jar" utility or one can use the facilities of their IDE to do so.
jar tvf filename.jar will show you the contents of a jar file without requiring you to extract it.
But I think that maybe what you are really trying to do is find the right coordinates for the dependency that you are missing, since obviously none of the ones you have right now are supplying the package you are looking for (in other words, checking their contents is not likely to help you).
I confess that the first place I would suggest to check is Sonatype's public Nexus instance. A search for your example turns up nothing, though. Usually that means the project is not trying to get their stuff into Maven Central or other major repositories (which is okay), so you have to resort to a web search. Usually the first two sections of the package tell you where to look (openanzo.org in your case).
If you are on Linux or a Mac, you could go to the terminal at the root of the folder containing your JARs and type:
# grep -ri "org.openanzo.client.jena" *
It will return a recursive list of all JAR files that contain that package name. If it returns 0 results, then none of those JARS contain that package.
If you wanted to do a more exhaustive search, you could unJAR the JAR files. The directory structure and .class files will be organized by packages in folders.
# jar xvf filename.jar
If you are on Windows, you can unJAR a JAR file using a tool such as 7Zip.
#Carsten
you do not have to rename a .jar file to .zip. You can directly open the jar file in winzip/or other zip utility (assuming windows OS)
#ashy_32bit
try using "jar class finder" eclipse plugin from IBM. Simple plugin for finding classes (if you know the class name)
OR
as carsten suggested... set the jar files as lib files and manually look it up
OR
create a batch file called a.bat (where you have all your jar files directly under a single folder) and paste the following 4 lines
#ECHO OFF
dir /b *.jar > allJarFilesList.txt
FOR /F %%A IN (allJarFilesList.txt) DO jar -tf %%A > list_of_packages.txt
FOR %%B IN (list_of_packages.txt) DO FIND /I "com/sun" %%B
NOTE the "com/sun" in the last line.. it is hard coded, you can pass as argument as well...
I know this is very basic form and can be improved "a lot" like looking up in various sub directories.
hope this helps :-)
.jar files are just ZIP compressed archives, rename it to zip, open it with your favourite unzip programm, and traverse through the directory.
If you add the jar file to a eclipse project, you can traverse through the lib in th project explorer.
HTH
Assuming maven downloaded the jar files,the files will be loaded in to a local repository.
You could use maven browser that comes packaged with Eclipse to browse and search for artifacts in your repository.(usually in userdir/.m2/repository)
Note:You can explore your repository directly if you want. You will understand the packages that were downloaded. But I suggest using the plugin.
If you are using Intellij IDEA, each project contains a tree called External Library that allows you to search and explore your libraries.

Resources