To create an eclipse project from just the folders - java

I work in an organisation where i am provided with a folder having codes and other things for particular application.
I want to open this folder in eclipse and be able to navigate to all the classes that are used through resources(ctrl + click).
The problem is when I imported the folder the eclipse worked same as that of a notepad. Any changes no error would be shown.
I even added the required jar files for that project.
What should I do? I just need to navigate and check out the classes that are used and declared. Pls Help.
P.S. - I work on Ubuntu Machine.

If you have a java project, you may need to configure the source directory(s).
This can be done by right clicking on your folder -> Build Path -> Use as Source Folder.

Related

Full java code from Netbeans Project

How can I get the full java code of a netbeans project? I have created a project for a contest, but need to submit the whole code. In Netbeans alot of the libraries and classes code is hidden. I need to submit all this. Even if a plugin needs to be installed.
Thank You :)
Assuming you have a NetBeans Project named HelloWorld in your system,let's assume that the default directory of storage of NetBeans Projects is in
C:\Users\USERNAME\Documents\NetBeansProjects\HelloWorld // On Windows OS
/home/NetBeansProjects/HelloWorld // On *nix(Linux,Unix) based OS
If it is different from the above,then please switch to the default directory of the Netbeans Projects.
Select your project folder from that,HelloWorld here.
It'll have several directories(folders) inside.
Switch over to src folder. All the .java files are placed in that directory. Those are the source code in Java. You can open and check and verify those files using any text-editor like Notepad,Gedit,etc.
NOTE :- DON'T DELETE ANY OTHER FOLDER/FILES unnecessarily,else,your NetBeans project won't be recognised/won't run properly.

Issues getting files from my friend to work on my eclipse?

My friend sent me a project from his eclipse workspace for me to take a look at, however when I tried to put the folder in my workspace it did nothing. I opened eclipse and nothing was there. So i tried to make my own project and just put the .java and .class files in their respected folders, but it still didn't work. Is there some special way I have to transfer them? I should also mention he has a windows computer and I have a mac if that makes any difference for file types like that. Thanks for the help!
If you can just take the .java files and paste them into your 'src' folder in a new eclipse project, you should have no issues. Just make sure you refresh your project in eclipse(right-click on project folder and click refresh, or click on it and hit f5).
This is what i normally do.
Suppose your eclipse workspace is D:\EclipseWorkspace and your project name is Project1.
Then i would copy Project1 in eclipse workspace on disk to have D:\EclipseWorkspace\Project1.
Then create a new java project in eclipse and when prompted for name provide name as Project1 (exactly same) and say finish. It will import the project automatically. Everything should be up :)

Eclipse Java Project - Open Declaration always opens class file instead of .java

I'm posting this query after doing lots of googling and trying out different options for last few days. Is there an easy way to attach source in Eclipse? is the closest answer I found to my question.
From above post, I tried all solutions but each time Eclipse is opening .class file instead of .java file.
Eclipse Details:
Kepler Service Release 2
Build id:20140224-0627
Please let me know if this is a bug with Eclipse or if I am missing something.
If you are using Maven, try this:
Double click on your project in eclipse -> Maven -> Enable Workspace Resolution
This is most likely because Eclipse actually use the class file for declaring the item you have requested the declaration for, and not the source file you think it should be using.
The typical reason for this is if you have a jar file containing previously compiled classes on your build path before (or instead) of the project containing the source you want. This is very rarely desirable as it can take quite a while to discover that your edits do not take effect.
Examine your build path carefully and ensure it is as you want it to be.
Maven is likely supplying a Classpath Container to your project, and generating entries for the Java Build Path based on the pom.xml contents (the JRE System Library is another example of this). Its entries will not have source attachment unless the container decides it will, which is why the Installed JREs preference page offers to let you set Source Attachments. If the pom.xml has something like that, see if you can use it. If not, see if you can configure the Maven container from its context menu. Otherwise, you may simply be stuck.
I had this same problem: when I pressed F3 or tried to open Declaration (after right click) for any element, it took me to the bytecode .class file.
My solution:
I went to the project in Project Explorer:
right click on project name->Properties
Then in Porject Properties window,
Java Build Path->"Order and Export" tab
There I selected the folder with the .java files (source code), which was below the folder having the .class files -in my case "JRE System Library [java-11-openjdk-amd64]", and pressed 'Top' button on the right frame. Then the folder with source files moved to the top.
Finally, pressed "Apply and Close" button.
That solved my problem forever and ever.
The folder
I installed a plug-in which allows me to download the sources for a maven project.
I'm not by my develop machine right now, but I think it was this:
http://marketplace.eclipse.org/content/m2e-dynamic-sources-lookup#.U8gjGWIaySM
With this, you can select a project an have maven download the sources and make then available when you navigate the code in Eclipse. All without "leaving" Eclipse.
Check into your project modules the Java Build Path, look inside the Source tab and verify if you have "Allow output folders for source folders" checkbox flagged; in this case you just need to uncheck it and you will be able to see again the right source from java files.
This is related to the Call Hierarchy in Eclipse IDE.
If you are in a situation, where you're seeing duplicate methods inside the call hierarchy showing Members calling 'myMethod(...)', double-clicking on one of the listed methods may open the .class file instead of the .java file.
When this happens, the solution is to set the search scope in the call hierarchy to Project instead of Workspace.
After setting the search scope, you won't be seeing duplicate methods listed in the call hierarchy, and double-clicking on the listed methods will only open the .java files.
(Using Eclipse DevStyle Dark Theme)

Attach the Source in Eclipse of a jar

I added a Student.jar into my Build Path in my eclipse like this-
Right click on the project->BuildPath->Configure Build
Path->Libraries->Add External Jars
There is one class named StudentTest in Student.jar file. When I was debugging my code in eclipse, I stepped into that StudentTest class in the Student.jar.
And after that eclipse shows me like this-
The JAR file S:\some_location\Student.jar has no source attachment.
You can attach the source by clicking Attach Source below
Now I am not sure how should I attach the source in my eclipse. And from where? Can anyone provide me step by step what I need to do.
Update:-
I tried unzipping the Student.jar and I got Student folder. And after that I tried pointing the source to Student folder But still I am not able to see the class properly so that I can debug it properly, it shows the same above behavior.
Use Java Source Attacher !
It does what eclipse should do - a right click context menu that says "Attach Java Source.
It automatically downloads the source for you and attaches it. I've only hit a couple libraries it doesn't know about and when that happens it lets you contribute the url back to the community so no one else will have a problem with that library.
Eclipse is showing no source found because there is no source available . Your jar only has the compiled classes.
You need to import the project from jar and add the Project as dependency .
Other option is to go to the
Go to Properties (for the Project) -> Java Build Path -> Libraries , select your jar file and click on the source , there will be option to attach the source and Javadocs.
A .jar file usually only contains the .class files, not the .java files they were compiled from. That's why eclipse is telling you it doesn't know the source code of that class.
"Attaching" the source to a JAR means telling eclipse where the source code can be found. Of course, if you don't know yourself, that feature is of little help. Of course, you could try googling for the source code (or check wherever you got the JAR file from).
That said, you don't necessarily need the source to debug.
This worked for me for Eclipse-Luna:
Right Click on the *.jar in the Referenced Libraries folder under your project, then click on Properties
Use the Java Source Attachment page to point to the Workspace location or the External location to the source code of that jar.
Go back in to where you added the jar. I believe its the libraries tab, I don't have Eclipse open but that sounds right. to the left of the jar file you added there should be an arrow pointing right, click that and 3 or 4 options expand, one of them being the source file of the library. Click on that and click edit(I think you can also double click it) then locate the file or folder on your hard disk, you probably have to click apply or okay and you're good to go, same with javadoc and i think the last one is native libraries. I don't pay much attention when I'm in there anymore if you couldn't tell. That's what you were asking, right?
I Know it is pretty late but it will be helpful for the other user, as we can do Job using three ways... as below 1)1. Atttach your source code using i.e, Right click on the project then properties --> Java build path--> attach your source in the source tab or you can remove jar file and attach the source in the libraries tab
2. Using eclipse source Analyzer In the eclipse market you can download the plugin java source analyzer which is used to attach the open source jar file's source code. we can achieve it after installing the plugin, by right click on the open source jar and select the attach source option.
3. Using Jadclipse in eclipse you can do it last not the least, you can achieve the decompile your code using this plugin. it is similar way you can download the plugin from the eclipse market place and install in your eclipse.
in jadclipse view you can see your .class file to decomplile source format note here you cannot see the comment and hidden things I think in your scenario you can use the option one and option three, I prefer option three only if i want to the source code not for the debug the code. else i ll code the option 1, as i have the source already available with.
Simply import the package of the required source class in your code from jar.
You can find jar's sub packages in
Eclipse -- YourProject --> Referenced libraries --> yourJars --> Packages --> Clases
Like-- I was troubling with the mysql connector jar issue
"the source attachment does not contain the source"
by giving the path of source folder it display this statement
The source attachment does not contain the source for the file StatementImpl.class
Then I just import the package of mysql connector jar which contain the required class:
import com.mysql.jdbc.*;
Then program is working fine.
I faced the same issue and solved using the below steps. Go to Windows->preferences->Editors->File Associations
Here click on Add
then type .class
click on OK
again click on Add
then type .classwithoughtsource
click on OK
Now you will be able to see JadClipse option under Java section in Windows->Preferences
Please provide the path of jad.exe file as shown below.
Path for Decompiler-C:\Users\ahr\Documents\eclipse-jee-galileo-SR2-win32\jad.exe
Directory for temporary Files-C:\Users\ahr.net.sf.jadclipse
click on Apply
Now you should be able to see the classfiles in proper format.
It is quite possible, just go to the jar in the Build Path and choose to attach a source just like follow.
Download JDEclipse from http://java-decompiler.github.io/
Follow the installation steps
If you still didn't find the source, right click on the jar file and select "Attach Library Source" option from the project folder, as you can see below.
I am using project is not Spring or spring boot based application.
I have multiple subprojects and they are nested one within another.
The answers shown here supports on first level of subproject.
If I added another sub project for source code attachement, it is not allowing me saying folder already exists error.
Looks like eclipse is out dated IDE. I am using the latest version of Eclipse version 2015-2019.
It is killing all my time.
My intension is run the application in debug mode navigate through the sub projects which are added as external dependencies (non modifiable).
I have faced same problem and resolved it by using following scenario.
First we have to determine which jar file's source code we want along with version number. For Example "Spring Core" » "4.0.6.RELEASE"
open https://mvnrepository.com/ and search file with name "Spring Core" » "4.0.6.RELEASE".
Now Maven repository will show the the details of that jar file.
In that details there is one option "View All" just click on that.
Then we will navigate to URL "https://repo1.maven.org/maven2/org/springframework/spring-core/4.0.6.RELEASE/".
there so many options so select and download "spring-core-4.0.6.RELEASE-sources.jar" in our our system and attach same jar file as a source attachment in eclipse.
Try removing the breakpoints. :)

After checking out Subversion code into Eclipse, how do I get it to build?

This problem has been frustrating me for some time...
A lot of sites like Sourceforge use SVN or Subversion to manage their code. I have little problem compiling SVN code in C++, but when it comes to Java, my IDE gives me a headache.
I've installed Subclipse for SVN support for Eclipse, and it works. I can check out any code into my Workspace. Now Subclipse will put the whole thing into a special project of some sort that can't be compiled. So I search Google for something and I come up with modifying the eclipse XML file to specify the 'nature' to be a Java project.
Okay, now it's a Java project. Say I have a folder structure like:
\src
\data
\graphics
I get 800 compiler errors complaining the package name is org.company.SomePackage instead of src.org.company.SomePackage.
Then what I do is create packages called src, data, graphics, etc, instead of just folders. I cut and paste everything in the folders into the packages and finally I can compile it.
What is a better way to do this?
EDIT: I can only check out anything SVN as a SVN project, and there's no way within Eclipse to change that to a Java project. How can I check out the SVN as a java project in the first place?
I get 800 compiler errors complaining
the package name is
org.company.SomePackage instead of
src.org.company.SomePackage.
Right click on Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
it thinks your source is stored in root folder. you need to specify to the project that /src is the source folder.
In general when we have an Eclipse project, which contains Java code – but we didn’t set it up as a Java project when we created or checked out this project, we are struck. And Eclipse doesn’t allow to change the project type inside the Gui. So we need to add the java nature as below.
1. Close your project.
2. Open your project file (which is located in your root directory of the appropriate project) called .project with your default editor. Search for
< natures>
< /natures>
and change it to as below
< natures>
<nature>org.eclipse.jdt.core.javanature</nature>
< /natures>
Save the changed file.
3. Open the project again – now it should become a java project.
Then do the following as explained by Kevin
On the Project Explorer Window ->Right click on the specific Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
For me when I went into “Source Tab” – the “src” folder was already added, but it was not giving me the desired result (ie I was still not seeing the .java files in the project explorer window). So I removed the “src” filed that was already added in the Source Tab and then added them again. And then all worked fine.
You have to configure proper source paths. Some open source projects make this automatic by checking their .project and .classpath files in with the rest of their files. For others, you'll have exactly the problem you are having. You need to set the classpath so the Java compiler knows where to find the source. You right click on the project and select properties and configure an arbitrary classpath, but the answer given by Kevin is easier for a beginner.

Categories

Resources