Eclipse: include source code while exporting as runnable jar - eclipse

I understand how to include other needed libraries or outside resources while creating a runnable .jar file in eclipse, but what I don't see is an option to also include the src .java files as well.
How could I accomplish this?

In the Export --> Jar File dialog you have the option to incluse source files and resources.
To make runnable a standard Jar File you only need to add/include an appropiate MANIFEST.MF on your own ...

Export to Runnable jar.
Open the Runnable Jar with WinRAR.
Click Add button, select the src.zip file.

I know this is answer is very late, but for those who still read this:
Eclipse has this option. You probably just did not notice it. I haven't checked since what version, Eclipse Luna has it for sure.
Export --> Jar File
then do not click Finish, but click Next.
You have more options there.
You will probably have to click Next twice to get to the Main Class selection.

Related

How can I connect TestNG javadocs to Eclipse?

Although we can find TestNG javadocs, is there a way to download a srcs.jar and connect to Eclipse?
Steps:
Download the jar file based on your version of testng, here. The jar file name should be like testng-version-sources.jar
Extract to one of the locations.
Then go to the eclipse project that you want to add source jar.
Short cut: Double click on any of the testng class/annotation in your source code, like double click on #Test annotation.
Eclipse tries to open Test.class source code. As src jar is not yet present, gives option Attach Source. click on the button.
select External location radio button.
select the jar file, which is downloaded.
Click on Ok. you will get the source code for Test.class (of course, for all other testng classes as well)

How to display the source code of an external JAR in Eclipse?

In Eclipse, I just imported an external JAR. Viewing any of the classes in the Package Explorer will instead of showing a source code open a Class File Editor with saying "Source not found". The folder of the JAR I have downloaded, however, has only JAR, no lib, no src, no docs.
Is there still a way how to view/generate a view the source code so then I can view it in Eclipse properly?
.jar files don't contain source code but are more like binary files for Java.
You can either get the source code from the projects page (if it is an OpenSource project of course)
An other possible way to view the source code of a .jar file is by using a decompiler (http://jd.benow.ca/; Also has a Eclipse plugin I think). This method can be very painful though when an obfuscator has been used by the developer who generated the .jar file.
Try this :
Download java decompiler from http://jd.benow.ca/ and now double
click on jd-gui and click on open file.
Then open .jar file from that folder.
Now you get class files and save all these class files (click on file
then click "save all sources" in jd-gui) by src name.
You cannot view the source form a .jar files as it contains binaries.Use a java decompiler instead to decompile the .class files and view their sources.
If possible I suggest you to use Maven for manage dependencies of your project, in most cases it did the trick for you.
See: Get source JARs from Maven repository

Eclipse jar file is not exported with project

I have a simple project that I need to be very easily imported into eclipse and started. When I export my project and import it again it comes with an error saying it is missing a required jar file. This jar file is added to the build path, but does not carry over when the project is exported. Why is this? I have been searching all day for an answer on Google and none have helped.
Would I just have to send the jar file along with the project and have the users manually add it?
Things I have tried:
Going into build path order and export and clicking the jar file.
using a clean workspace for the import / restarting eclipse.
For anyone with a future problem like this one. I was putting the jar in the lib folder and also adding it to my build path, but the jar would not export over. When I added the jar to the WEB-INF / lib folder it successfully carried over with the export.
You may want to try this:
Right click on the imported project select Build Path -> Configure Build Path -> Java build Path -> Libraries Tab and check if the jar file which eclipse says missing is present in the Libraries tab.
If it is present then select it and click Edit, a "File dialog" will pop up, find the desired jar which is in your computer's directory. and click Ok then wait for eclipse to build
the workspace. If it is not present then add it through Add JARs... or Add External JARs...
Export it as an Archive file of the project rather than a jar. Then it's just a matter of someone else importing it as an Existing Project. Exporting it as a jar is only something you do when you want to deploy the jar and run it.

Netbeans newbie-- How to enable viewing info from a javadoc JAR file

I have some JAR files which I have to add to a Java project- for each of those JARs I also have separate JARs that contain Javadoc for each of the jars-- now I want to be able to view information from the Javadocs in Netbeans.
How do I do this? I am using Netbeans IDE 7.3 on Windows 8 x-64.
when you download some JAR in zip, you will find usually 3 files in there :
example.jar
example-sources.jar
example-javadoc.jar
In your project import example.jar as libarary. After that go to your Project (right click ) then Properties >> Libraries >> Compile then select your jar file and click EDIT, in that form select javadoc and sources file :)
Here is image for easy navigation (itextpdf lib is in thi example)
EDIT
There is even faster way ;) Right click on JAR in Libraries section of your Project and select Edit from menu. Its the same form as in example above.
Go to: Tools>>Java Platforms>>Javadoc tab
There you can set what Javadoc you want to have.

Eclipse : How to remove the attached Source which was added to a Jar

I am using Eclipse IDE (Helios Version).
As part of the build path, I have a jar file for this Application, I have attached the source code for this jar file using Attach Source Option.
Please tell me how can I remove this attached source for the jar file?
Open the .classpath file and delete the source attachment part.
Or in the Build Path control panel, find the jar file and remove the source attachment (it is one of the detailed options there).
If you have two different projects in eclipse that are linked, the best way is to open both of them in eclipse workspace. If you do that, you don't need to "Attach Source..."
If you added the second project as a Source Attachment by mistake, you could try to remove the projects from eclipse workspace and adding them again. That worked for me.