Where can I get the source code of the servlet-api.jar? - java

I have a project that uses servlet-api.jar. When debugging, I wanted to step
into its classes (such as HttpServlet), but I got "Source not found attach source ".
Is there a way to get the source like all the Java sources? It would be good to have so I would be able to debug it and to step into the code.

You can get apache source code from the apache tomcat website: http://tomcat.apache.org/index.html

The Servlet API JAR is just interfaces (along with a few minor utility classes); there's nothing to step into.
Depending on your app-server, you can download source for implementation classes like HttpRequest (for Tomcat, instructions are here). However, why do you feel there would be value stepping into those classes? They generally work well, and any problems are almost certainly in your own code.

In addition if you are in eclipse or netbeans, and are using maven based project right click on the dependencies and download sources for your particular dependency.

You can get the source from java2s.com
(version 3.0 of the servlet API): http://www.java2s.com/Code/Jar/s/Downloadservletapi3020100224sourcesjar.htm
(or the older version 2)
http://www.java2s.com/Code/Jar/s/Downloadservletapi256114sourcesjar.htm
In fact java2s.com is a huge java source, program & jars resource.

Intellij IDEA
Download source codes from Apache, put somewhere at some stable place in your computer.
Try to go into some .jar function until "decompiled" result shows.
Click "Choose sources".
Select downloaded source codes and IDEA will do the rest :)

To checkout the Javadoc on the classes or methods of "servlet-api.jar",
visit
http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.27/src/
(for other versions of tomcat visit -
http://archive.apache.org/dist/tomcat/tomcat-8/
and navigate to their "src" directory,
and download zip file for Windows(tar for Linux.) and finally
attach it within the IDE(Netbeans, Eclipse, etc.)

When you download the binary distribution of the apache tomcat, you can also download the corresponding source code distribution(on the same page).
Simply download the source code distribution zip.
move it to somewhere inside tomcat apache folder
Point to source code distribution zip when Eclipse asks you for the source code attachment.

Related

Installation of metadata-extractor

I'm stuck on installation.
I downloaded Maven, but I'm not sure which file within
the metadata-extractor folder (that I downloaded from the repo) to use as the target.
I tried all the files at the top level.
All attempts have failed, e.g.
java -jar metadata-extractor-2.13.0.jar build.gradle
com.drew.imaging.ImageProcessingException: File format could not be determined
I am using v2.13.0 of the meta-data extractor
I've just started to code and took interest in this project but also had issues using it. Instead of using Maven i just downloaded the source code from github and threw the 'com' folder into my myproject/src folder. Then i downloaded the xmpcore-6.1.10.jar library and added it to the Build Path. Got it working that way. I hope someone will give you a better solution but if you just wanna do something right away, you can try this solution.
Try downloading IntelliJ and create a "new project from version controll". Use the URL given on the GitHub page (under download/code). That will save you a lot of problems.

Why JAR Files Do Not Contain Documentation?

I'm in the process of writing a small Java library that contains a related code that I usually include in most of my android app. I decided to export the library as a jar file then drop the file in the libs folder of my future projects.
Using Android Studio:
I created a Java Library module and put my code in it. And I added some comments to some of the method, following this.
Then, I ran the jar task in gradle, which gave me the .jar file in build/libs directory of my module.
Now, when I used this jar in one of my android apps, Everything works as expected, except the Doc part. When I hover over the classes and methods of my library, I don't see the Doc comments that I wrote.
Q1: Am I missing another step?
Q2: Are jar files supposed to have no comments?
The javadocs are the documents that are generated from the javadoc comments in your source code. They are not part of a normal JAR file because that would unnecessarily bloat the JAR files ... with stuff that someone running to code doesn't need.
The javadocs can be generated by a Gradle task, by the javadoc command (if you have a Java SDK installed) and by various other tools. You can then read them using a web browser.
On the other hand, IDEs can often render the javadoc comments in source code and display them as pop-ups, etcetera. (Some people would call this "javadocs", but I think that is an overstatement, since you typically can't navigate the documentation ... like you can with read javadoc documents.)
In order to render the javadoc comments, the IDE needs the source code. JAR files don't (normally) contain any source code or javadocs. Instead, the normal way to deal with this is to tell the IDE where the source code is, either by pointing it at a source code directory, a ZIP file containing source code, or URL for downloading the source code.
(I don't use Android Studio, so I can tell you exactly how to do this. However, I imagine that the IDE's online help explains how to do it ...)
It seems that your end goal here is to distribute your libraries in a way that allows programmers to see the javadoc comments.
The simple way to do that is to distribute source code. This Q&A describes how to get Gradle to generate a separate archive containing the source code, or add the source code to the JAR containing your compiled code1.
If that isn't acceptable, you may need to generate the javadocs as HTML2 and provide the HTML tree as a separate ZIP file that a programmer can unzip and read with a web browser. Alternatively, put the javadocs up on a website.
1 - I would not recommend this. People who just want to use the JAR as a binary are liable to complain about "bloat".
2 - If neither providing source code or javadoc HTML documentation is acceptable, I don't think there is a pragmatic solution.
There is a separate Gradle task to generate javadoc. Try adding the following:
task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir }
And then run:
gradle javadocJar
See if that helps.
In addition to the above, you can try and add the following to make to generate a single jar with both compiled classes and javadoc:
jar {
from javadoc.destinationDir
}
jar.dependsOn javadoc
I don't know if that's the right decision to bundle everything in the same jar. I prefer keeping the jars separate and maybe find another way to make the IDE use the javadoc jar file. Maybe try adding the javadoc jar as another dependency of the module.
Yes This is possible
Hi, This is possible but with a small change like in the jar file.
First of all, from a code point of view jar file contains only compiled ".class" files and not source files ".java"
So if you need a doc to be applied with a jar by this I mean not the index.html which gets created but the comment that appears whenever a person uses the jar API and calls a method with a suggestion.
Example :
For that, we need to also add a source file while generating .jar file.
Steps for the same:
Type comments/java docs in code
Generate Docs
This will create a doc folder in project folder
Now create jar file
Make sure you choose this option as shown below
Almost done just test it by importing jar to another project and it should the suggestions as per docs
Very Important this can be harmful as you are including source files.java in your jar so before making make sure if you need this or not.!!!!
Hope this gave your answer
Any questions you can contact me over: VaibhavMojidra.com

Importing an API (UniprotJAPI) into Eclipse

I downloaded an API from Uniprot, which is a protein database, to play around with their code. This is my first time working with an API. The API contains a folder of source files (which includes example code for developers), a folder for classes, a library of JAR files, and an executable command file to run the example code (in cmd, I must execute: runExample.cmd InsertExampleCodeHere )
How do you edit this API? I tried making my own Java project, linked it to the JARS I downloaded, and also transferred over the executable cmd program to my Java project folder. At first, I copied over some of the example code, and added some print statements. When I saved my changes and executed the cmd file, my main class cannot be found. If I tried compiling my java project, I get a bunch of errors - and these errors apply to the example codes Uniprot provides (and while linked to the library of JARs). Is there a particular call (or special command) I must make when compiling my projects?
Thanks in advance!
Hmm, not sure myself as the only real API I was using was a JSON one so I could easily parse it. But, assuming you have a folder that contains of all that, I would imagine you could try to just copy it over to your project's folder and then just add it to build path in a similar vein to how you would add jars. At least that's what I can think of.
Also, you could try this which is a solution I found from the Stackoverflow question titled "How do I important the javax.servlet AOI in my Eclipse project?"
Quick Fix- This worked in Eclipse - Right Click on project -> Properties -> Java Build Path (Tab) -> Add External JARs -> locate the servlet api jar implementation (if Tomcat - its named servlet-api.jar) -> click OK. That's it !!

How to set a classpath automatically during the installation of an excutable java application?

I am writing down an example of what I was trying to do.
But this is just one example, I am sure there would be many. So I want a generalised answer for this.
I was trying to make a java desktop application which reads the word documents. I realized I need some Apache libraries/APIs that would help me do it.
So I downloaded the library.
But now I need to set the classpath of the files from the library.
I am a developer and I can do it, but imagine giving such instructions of setting a classpath to a complete non-developer user.
I was wondering if when I am over with the making of this java application, I would make it executable (exe) application and when someone installs it, the classpaths are set automatically during the installation and the apache library files are automatically extracted.
How can I do it? Can someone explain me in detail - step-by-step?
Please consider using some development IDE, like (free) eclipse for instance.
Then crate new folder (clled lib for example) in your project, copy the library into it,
then click on your library by the right button and select "add to build path"
As already mentioned - best way to do it is to use Manifest file in your jar. Official documentation: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Install [java library] in Eclipse

I just downloaded Eclipse several hours ago, and needed to add Java3D to the classpath. Installing it went without a hitch, but Eclipse can't seem to find the documentation folders so that it can give super-IDE functionality, such as autocomplete and method signatures.
While I know how I would add them individually, this lead me to the question; what is the "correct" way to install a Java library in Eclipse? Is there a special directory format I should follow? Is there a plugin that already did this for me? (The answer to that is yes, but I don't know how to use it, or whether or not it's appropriate).
Thanks!
Edit 1: It seems to me that someone down-voted the question. May I ask why?
Edit 2: So after monkeying around with the JARs, it seems that manually setting the doc path for each JAR in the library seems to be the least-error prone way.
when you add a .JAR(library) to your project in the LIBRARIES tab for your project, you have the option of attaching the javadoc directory for the jar.
So, go to the LIBRARIES tab of the "java build path" for your projects. select your jar. expand the (+) sign and you will see that you can set the javadoc. path.
good luck,
I think I've got it (had the same issue as you). Better late than never.
Go here - http://java3d.java.net/binary-builds.html and download the documentation zip (j3d-1_5_2-api-docs.zip).
Extract the directory anywhere on your HD (Right in the Java3d folder is fine).
Link the Jar's JavaDoc listing to that Folder (java build path >> Libraries >> expand the Jar Listing >> JavaDoc Location >> browse to the folder location, then validate). Do it for each j3d Jar.
That should integrate the J3D Javadoc.
As far as I know (haven't used 3.4 very much thus far), Eclipse has two options for the automatic showing of Javadocs. The first is a JavaDoc jar to attach to the jar file. The second is having the javadoc in a source jar which is attached to the jar to show the source.
A directory, if I recall correctly, will not provide autocompletion of javadoc. However, if you press "F1", you will be able to access the javadoc via the help menu.
You might try placing the documentation directory into a jar file, and attaching it to the jar file and see if that tricks Eclipse.
I cheat; All my java projects are built with maven, so I use maven to generate an eclipse project, with classpaths etc already setup, with a simple 'mvn eclipse:m2eclipse'.

Categories

Resources