Jar file which contains the Javadoc? - jar

Is it possible to create a jar file which contains the javadoc ?
For now, I'm creating a jar file & javadoc folder.
1. I want to create a jar file that contains the javadoc , can I ?
2. Can I do so without attaching the source code into the jar file ? (just the jar with javadoc) ?
Thanks

The short answer is yes. A jar file is just a zip with a manifest and additional features. You can put any type of file in it, including images, html files etc... All you have to do is jar your javadoc folder exactly as you would do for a classes folder.

Related

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.

How to create runnable jar with images and sounds in Eclipse?

I'm trying to create a jar in eclipse. The project contains images and sounds.
I have Resources folder with more folders, but when I run the jar is without the images.
The project structure:
Example:
btServer.setGraphic(new ImageView(new Image("file:Resources/buttonimages/Server.png",100,100,false,false)));
Make sure when you are exporting your Runnable JAR file, you are selecting 'extracting required libraries into generated JAR'.
The other workaround is to put the resources folder from your workspace in the same file location as your jar file.
Hope this helps

how to compile a java file which is in a jar and then re-create the jar

I have a jar file (Gestp.jar) . And I have some .Java files (which are web applications) within the jar file
I need to modify a particular .Java file . And then re-create the Jar file and deploy it in a server.
I have extracted the jar file , and did the modification to the .Java file. But unable to create the .class file with the changes , in eclipse as it is a web application.
Please help.
Thanks in advance,
Aditya.T

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 create a jar file, which includes xml and html files?

I am trying to create a jar file which includes some class and java files needed, but I also would like to include some extra xml, xsl, html, txt (README) files.
I am using Eclipse on Windows XP.
Is there an easy way for me to set up a directory structure and package all my files into a jar?
Add the files to a source folder and they can be included in the jar.
One common way is to have, at the root of your project, a src folder. Within that, folders for java files, and others. something like:
src/
css/
java/
html/
images/
Then you can make each of those subfolders a source folder (Right click, Use as Source Folder) and they should be available to add to the jar.
A .jar is nothing but a ZIP archive, so you can use any program capable of creating ZIPs. Just make sure that you include the manifest and all the class files.
I just added all the files into my Eclipse project (including the txt, html, xml, etc files).
Then I used Eclipse to File->Export->Jar File->Next
Check the "Export Java source files and resources" box.
Done.
If you're using Ant, you can use the jar task (see the examples section for how to include/exclude certain files, etc.)
If you move to an ANT (or Maven, for you Maven fans) then you can automate the Jar building very nicely, and also use it outside of Eclipse (e.g., in an automated build environment). All you need to do is copy the files from your src, jsp, foobar and resources locations into a build staging folder, then Jar the resulting files using ANT's Jar task.
<target name="makejar" depends="compile, copyfiles">
<jar destfile="${jars.dir}/myjarfile.jar" index="true" basedir="${build.dir}" />
</target>
One thing I look down on is including non-source (except package.html files for Javadoc) within the src folder. If you feel you have to do this to achieve something, then you are doing it wrong.

Resources