I am currently studying at university and based on other peoples recommendations I am beginnning to read other peoples code.
i have found and downloaded the source for an open source java project, that seems quite interesting. I want to load this project into an IDE (netbeans or eclipse), so as to make it easier to read and navigate. However both IDE's say that the project is not recognised. It is not only this project, but any project I have attempted to load.
How do I load a project (ie. a file structure of source files) into the above IDE's as a project.
Thanks in advance,
Sam
In Eclipse, select File, New, Java Project, give the project a name and then select Create Project from Existing Source. You should then select the src folder that contains the code that you'd like to use.
Eclipse should then create a new project containing the source. To change the project settings e.g. source folders/external jars, right click on the project in the Package Explorer and select Properties, Java Build Path, Source and make any appropriate changes.
Actually there is a cool trick with Eclipse, you should be able to just select the class that you are interested (select all of the text from your browser), and just paste this in Eclipse right on top of a project, it will automatically create a class for you. It's very handy when working with SWT snippets for example.
You need to have created an Eclipse project first. But you can just create one project and put any number of classes in it.
If the open source project in question uses Maven as the build system (i.e., there is a pom.xml file in the root of the project) and you have Maven installed, you can run 'mvn eclipse:eclipse' to build the project files for eclipse to use. Then just use File > Import and select existing project into Workspace and point it at the root of the project folder. Eclipse should then import the entire project with the appropriate libraries. There are also plugins that work for NetBeans and Idea I believe.
Related
Whenever I create a new maven project in vscode, the Java Project extension doesn't update as the file explorer does, so I have to manually clean the workspace caches to make it synchronized. Also, the only file category I could add in Java Project view is the .class files, so I have to quire with the explorer. In some cases, suppose I need to add the same file in two or more nested folder like src and target, which is confusing, it' s never the case in eclipse and other refined editors for java, is there a way to solve these two problems?
I will publish my operation steps in the answer. You can also refer to the official documents for more information on project management
Creat java project
Creat a new floder to save Maven
Vscode automatically generates Maven project and workspace environment
There is no need to empty the workspace. Of course, if you want to create a project in the original directory, it may cause similar problems.
For your second question, I think java project only manages Java classes. If you want to put other file types, why not use file explorer.
Java project has its own things to do
I have a fully working pure java project and a fully working Java & C++ sample project in the same workspace. I decided to copy some of the C++ elements from the sample project and get them working in my previously java only project.
Eclipse seemed to know about how to handle the C++ parts in the sample project. Indeed I could delete the .so file in the libs/armeabi-v7a and then ask eclipse to rebuild the project and hey-presto a new .so file would appear and the program could then run again. Unfortunately the same could not be said of my original project. Eclipse seemed not to know what to do with the files in /jni, i.e. clicking on build project would not create an .so file (though I could create the so file from a DOS command line by typing ndk-build). Looking at the properties of the two projects I noticed that in the sample project, under "builders", it listed (amongst other things) a "CDT Builder" whereas in my original project it was not listed. I assume that this is the cause of the problem, but I can not work out how to get CDT Builder listed in my original project's properties.
Solved: Highlight project name in eclipse, then right-click and select android tools > Add native support. Then add a dummie name for a library and click finish. This dummie name will appear with a cpp extension in the project's /jni directory. The CDT builder is now associated with the project. You can then delete the dummie file if you don't plan to use it.
I cannot find "create project from existing source" in Eclipse Indigo while I am trying to create a "java project". When I select Java project and then next window comes up with options-
User default location,
JRE,
Project layout, and
Working sets.
I couldn't find a clue while searching for any possible change in UI of Indigo. Where can I find "create project from existing source" in Indigo?
Un-check the Use Default Location option and then Browse to select the parent folder of your existing source tree. Eclipse will automatically detect the existing files and folders, although you might have to configure the project to let it know what your source folder is; but the New Java Project wizard presents that option to you.
If your source directory is inside the current workspace, ERiz's answer won't work due to a bug in Eclipse. (It prints out the error "folder overlaps the location of an existing project"). Instead, you should leave Use Default Location checked and type in the name of the folder as your project name.
See here for more discussion about the problem.
So far it seems the only way to do this is the solution Antimony suggested.
If you want to avoid typing in the folder name, untick "Use default location", select your source directory, then tick "Use default location" again and the Project name field should contain the name of the source directory.
I came across this answer trying to import a Git project, so I will write my solution here.
The workspace directory is the same as the Git's working directory, so I didn't want to move the project folder somewhere else.
If you have a Git project you want to import, but Eclipse can't see it because it has not the .project file in its directory, here's the steps:
File > New > Java Project: put in the name the name of the project's dir, so as Antimony said, the project will be automatically configured.
You will see your project in the Project list, but it's not bound to Git yet.
If it's a maven project, you can convert it to maven project now: right click on the project and select Configure > Convert to Maven project.
Delete the project (DO NOT SELECT "Delete project from disk")
Now you can import the project as a Git project from File > Import > Git Project
I've been tasked with picking up someone elses Java code and adding some functionality to it.
I'ved pull down the source tree from CVS and see a bunch of .jar files in different folders. I'm guessing the developer did not use Eclipse.
I am new to Java (coming from .NET background) and have used Eclipse so far to create one Java project. I'm wondering now that I have this guys files (he has classpath.jar and other .jar files along with some subfolders each with 'java' files in them), how do I open them? I tried opening one at a time, etc.. but doesn't seem to work. IS tehre an easy way to do this? I thought there' might be some kind of 'import existing code' thing in Eclipse but I can find it. How can I do this? Do I re-create the folder structure and just add the existing files one a time?
Thanks much for any help
something like 'create project from existing source'?
http://www.stanford.edu/class/cs108/JavaTools/eclipse-guide/
if the existing code is not structured well, you are either going to have to heavily configure your project sources, or just change the project structure.
File -> new
Than select general->folder.
To make developing easier in eclipse i recommend some refactoring to the project.
create a new eclipse project using the parent folder as the home.
every folder that's the root of a hierarchy of java classes becomes a folder in the "source" tab (either on creation, or add through "project->properties").
every jar (at least the ones he's using, there may be extras) gets added in the project->properties libraries tab.
This is assuming that all of the hierarchies belong together and that the thing isn't structured to build little sub-projects out of pieces of the hierarchy. If there's a build file for this thing you might want to be sure that if the build file is doing that you're building things appropriately.
File->Import->General->Existing Projects into Workspace
OR
File->New->Java Project
This will create a sample java project for you. You can add the files appropriately.
Below is an example of a j2ee Project:
http://java.sun.com/blueprints/code/projectconventions.html
If C:\Workspace is the folder you are using as the workspace and you have your existing project placed as "C:\Workspace\ExistingProject"
Open Eclipse Got to File->New Project
Select the type of Project you want to create Use the name as "ExistingProject" for the project and click Finish or complete the remaining steps of project creation wizard normally.
Internally a .project file would be created in the ExistingProject folder and a .metadata folder would be generated under Workspace folder.
If you want to place the ExistingProject not under the workspace u follow the same steps.
There's 2 possibilities:
Import project from file system:
Create a blank Eclipse Project.
Then select File -> Import -> General -> File System. Select project, and point it to your created project.
Importing from CVS
Goto File -> Import -> CVS -> Project from CVS
Enter your CVS Host, Repository Path, Username and Password, and click next,....
Add what you need and click next (follow the instructions) until you're satisfied and click finish.
Hope this helps.
A simple tutorial that incorporates my 1st option and commmits it to CVS: http://thedesignspace.net/MT2archives/000662.html
Two options:
Maven - highly recommended but rather read this: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html than have me re-write it here. Maven might seem like more effort up front but it pays for itself a hundred times over during the course of even a simple project.
Do it yourself (assuming Helios):
Move the source code Java files to ~/development/MyProject/src/java. Move the jars to ~/development/MyProject/resources.
In Eclipse, File > New > Java Project. Type in your project name.
Untick "Use default location" and browse to ~/development/MyProject.
Select src/java as your source folder (if Eclipse doesn't pick it up automatically).
Finish.
Then, for each error, you will need to find the corresponding JAR and add it as a library to your classpath in the project properties.
The important thing to bear in mind is that Eclipse is not like Visual Studio - you cannot easily just edit one file at a time and that is not what it is designed for. People can get frustrated with Eclipse after working with VS but if you just allow it to do things the way it wants you, your life will be much easier.
trick is finding the root folder. Generally, developers use the following:
project root
-- src
-- bin
at least, what's what Eclipse does by default. There are other ways it can be organized as Maven uses the following:
project root
-- src
-- -- main
-- -- -- java
etc...
More info on how Maven standardizes here:
That said, finding out how the source is organized shouldn't be too hard. Open up one of the .java files and look for the line at the top that starts with "package ". Should be something like this:
package com.somecompany.client.utils
Note, that's just an example, it won't be that exactly although it should start with "package". The value after package represents the path that the file should be in relative to the root of the source folder.
source
folder/com/somecompany/client/utils
So, if you follow the default way that Eclipse organizes things, it should look look like this:
project root
-- src
-- -- com
-- -- -- somecompany
-- -- -- -- client
... etc
SO, as other people have mentioned, you'll import from existing filesystem, point to the folder at the project root. You may need to configure it to point to "src" folder as a source folder. You may also need to import those .jar files into your project as well.
Good luck
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.