Finding source jar for binary jat - java

Example of situation. I use xercesimpl-2.8.1.jar in java project(Eclipse).
It's linked as a library. For debugging I downloaded xercesImpl-2.8.1-sources.jar.
I paired two these by:
Eclipse Project: Properties\Java Build Path\Libraries\Source Attachment
Browsing in source code for some type, them "Change Attached Source".
Both had no effect implying that 2 jar are strangers. However, reviewing of archive contents predicts they are similar.
Questions:
How (best practice) to find source for binary jar?
How to pair it in project?
What's in structure makes them able to pair?
Is it Eclipse or jre component that links them together?
Thanks in advance.

You should make your project a Maven or a Gradle project and define the Xerces library as a dependency. Then Eclipse or IntelliJ IDEA could get the source code of the dependency automatically, in case there is the source code in the repository. In most cases there is a source code in the repository.
For example Xerces:
https://mvnrepository.com/artifact/xerces/xercesImpl/2.8.1 (definition of dependency)
http://central.maven.org/maven2/xerces/xercesImpl/2.8.1/ (files in the repository)

Related

what is the equivalent project file for a Java project?

What is the equivalent project file for a Java project? For example, a C# project file is denoted by the delimiter of .csproj. So what would it be for a Java project? Is it dependent on what IDE I am using for Java?
I did some search online about this and it seems to me that the answer to this question is dependent on the IDE. From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated. I do not want to be steered in the wrong direction on this and so I want to first ask around for guidance.
You're probably looking for the build file, not the IDE project definition.
Is it dependent on what IDE I am using for Java?
Yes. IntelliJ has .iml files, and Eclipse has .project (that's not a file ending - that's the file), as well as .classpath, .factorypath, and more. But, many of these are effectively generated or just refer to the build file. In C that tends to be called Makefile, in the Java ecosystem, Gradle and Maven are the 2 most popular build tools; they have build.gradle and pom.xml respectively. These would be more useful as basis for knowing how a project is 'put together', so to speak.
From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated.
That's very basic and should rarely work except for the simplest projects. For example, most Java projects have source files, test files (also source files but they are not part of the distribution), and resource files (non-Java files that are also needed for the app; think about the images for the icon on a button), as well as a ton of dependencies (third party libraries used by the Java app).
Given that folks like many IDEs, the IDE 'config file' is not what you are looking for, and many projects don't even check these into source control (and probably shouldn't). Together with the source, you have a build file. This build file knows how to download dependencies, compile every artifact (there doesn't have to be one; maybe there's the test code to the built, the main app, a plugin for some other tool, and an installer. Build tools can handle all that), run the tests and report on them, possibly even tell you about code coverage, and they usually can run the app, but more generally, you just want to tell the build tool to build a distributable for each relevant artifact.
Those build files are what you're looking for. With those you can build your project, or point an IDE at them and then you can edit the project with all the dependencies and classpath linkages all worked out for you.

imported guava source code in eclipse is not runnable

I need to write some Unit-Tests for google guava 15 (for an online course).
There is a semi-automatic tool involved that reads the source code and executes it with the help of eclipse. So I need readable source code (not only the binary classes) that can be run from within an unittest.
So here is what I did:
cloned github repo via egit
Import from git -> local repository -> general project (I tryed new java project and the new project wizard but that created empty folders, only with general project the source was at least visible within eclipse)
went back in git history to guava version 15
But it seems that he doesn't build the java project now (of course because its a general project). I found some answers to this topic: editing the .project from eclipse to change the general to a java project but that did not work, maybe I did it wrong).
But is there an easy way to do this? Maybe by using a build tool or something? Seems to be very complicated to edit the .project for a complex project like guava, only telling him that this is a java project does not work!?
Guava is designed to be built using the Maven build tool.
If you want to do this within Eclipse, the M2E plugin implements Maven integration. It knows how to import a Maven source tree as an Eclipse Java project, including setting up the ".project" file and other stuff that Eclipse needs.
Here's how to install it: Maven in Eclipse: step by step installation
This is somewhat detailed answer on how to get a Maven project in Eclipse working and manage it by EGit. It describes almost the same situation.

Attach Sources - Maven Dependancies [NetBeans]

I am running NetBean 7.4 on Mac and I am sort of new to Maven dependancies.
I have been given a project that uses Maven to download a framework for networking simulation.
Turned out that the framework has a bug and the teacher gave us a public GitHub repository with all the source code for the framework, so that we can also modify it.
How do I connect the GitHub link (with sources) to NetBeans in order to being able to modify the framework classes? The "Attach Sources..." button that appears on the framework classes asks for a JAR or ZIP (if I download the ZIP from GitHub it doesn't work).
Moreover, it looks like the framework files in the Dependancies folder cannot be modified anyway (read-only files).
Thank you all.
to "connect" 2 different projects, the checked out source's version needs to be equal to the version in maven pom.xml.
So clone the github repository, figure out which branch/tag matches the version in your project and check it out. Then open the project(s). If you did that correctly (and assuming the github project is actually maven), your project's dependencies section will list them with project-like icon. Then the projects are linked.

What is the correct way to have a Java Project with Eclipse on GitHub

I am working on a Java Project with Eclipse which we want to put on GitHub so that it is accessible for the public. But we are not entirly certain what is the correct way to put a Java Project onto GitHub. We have already made a GitHub and uploaded a Java Project. But when checked it out, with EGit, to my computer all the folders are now packages.
Is there any way how this can be avoided? How are you uploading a Java Project to GitHub? Are there any difficulties which we are not aware of right now?
A good example I like to use, is my getting started with selenium project.
This is a Maven enabled Java Project that is hosted on github.
But when checked it out, with EGit, to my computer all the folders are now packages.
This is because of your .classpath. If a source folder is added, (like src/main/java) any subsequent folders will be "packages".
How are you uploading a Java Project to GitHub?
Just as you see in the project above. Upload everything, except binaries, and jar dependencies. (which is why i use Maven)
Are there any difficulties which we are not aware of right now?
Where I work, we use a process in which our projects on github are entire java projects. I've heard that it's bad to upload eclipse specific things like .project, but even individuals who use IntelliJ IDEA, it doesn't seem to be an issue, because they can just upload their .file.
One thing to keep in mind, is your .gitignore. Make sure that /target/classes/* and other java specific compilations are avoided as you want your repo to be only source code. (one thing i DID forget to do on that project above.. will fix ;))
I'd rather not upload .projects or .idea files while uploading projects to VCS system (git or not).
I add these folders to my .gitignore file (wich i upload to VCS)
Regards.

how do I add open source API code to an eclipse project?

I have to write a java application which I'm putting together using eclipse and it relies on open source code. This application needs to be self-contained, meaning that I'm supposed to create a jar file that has no external dependencies.
I can use the open source code when I reference the jar files in the project's build path, but the idea is to have the actual source code as part of the eclipse project, side-by-side with my code.
The source code can be found here: http://hc.apache.org/, but when I import an existing file system into my project I can't quite get things to work. The packages end up with the wrong names, breaking references, and I can't do anything. Notice that the folder containing the source code has this structure:
httpcomponents-client-4.2.3\
src\
httpmime\
httpclient-osgi
httpclient-contrib
httpclient-cache
httpclient-benchmark
httpclient
fluent-hc
each of those subfolders has src/main/java/org/apache subfolders.
Can someone please explain how to do this? Am I supposed to import everything one java file at a time?
Use a tool like OneJar, FatJar, JarJar, etc. to create a single-jar application.
As Charlie mentioned, the Maven Shade plugin is another choice, particularly if you're already using Maven. If you're not, consider it or another transitive dependency management tool.
Some tool should be used, IMO, and it's more important the more dependencies you have.
Alternatively you could use a jar class loader and include the jar file in your artifact.
I would most definitely not include the source of dependencies in your own project.

Categories