Can you import a non-archive project directory in Eclipse? - java

I read this article which shows how to import/export projects in Eclipse (although it seems a little outdated and I'm using 3.7 Indigo).
To export a project, you go to File >> Export and it creates some kind of "project archive" file on the local file system. You could then email it to someone else, who could then import the archive as a new project or into an existing project.
But what if you don't have an "archive" file to begin with?!? What if you just have the project files and directories but without all the Eclipse-metatdata (.project file, etc.)? Is there anyway to tell Eclipse to look at, say:
/home/myuser/some/path/to/project/root/
src/main/java
SomeObject.java
build.xml
...and get it to read that as a new Java project?

Try the steps below:
Create a Java Project in Eclipse as below:
Load the project contents from your file system as below:
Hope this works for you.

.project and .classpath files are the base of the project structure. Without a .project file Eclipse won't recognize your project. The .classpath is important too but that one changes between environments. Should you use the files from another environment you'll have to reconfigure some settings.
Rather than emailing code, I suggest you use a Version Control system and, also, some Eclipse plugins. SVN + Subclipse for example.
If you trully want to send the project to another person just send him the project's folder and import it as an existing project by doing right click on the project explorer and selecting Import > Existing Project into workspace.

Related

Problem with source of my JAVA Project- Can not upload it to Eclipse

I have a basic but important question.
Our client has an application that has been written with JAVA. We need to modify something in one of the classes.
They passed us the Source files of this project, but I really have doubt that if they sent us the source or no!
This is the structure of zip file:
But when I import it to Eclipse (Import Existing Project to workspace) I see the error that is saying: "No projects are found to import"
How can I be sure if they sent us the source?
Actually I want to be sure and then ask them...
I tried also to open it with Apache Netbeans but it says "No Netbeans projects added".
Can anyone help me about this?
Thanks
Sep
The complete build structure does not look like a default gradle/maven or even Eclipse/Netbeans IDE style (as mentioned already by greg-449)
Howto import plain sources into Eclipse - without maven or gradle
Normally a eclipse project setup looks like
/.project
/.classpath
/src/java
Hello.java
/test/java
HelloTest.java
/bin
Hello.class
HelloTest.class
So I would do following
Create a new Java Project in eclipse and use as customized project location your root folder of your source files.
When asked for source folder location you can either use /src/java (when you
you are free to restructure the files), or add all folders where
sources are located (e.g.maybe nbproject contains sources ?) as source
folders of the project.
Libraries: If the project contains dependencies and you want no compile failures, you must add all libraries to your eclipse project. When you can start the (ant ?) build you will have all libraries inside build folder. Add those to your eclipse project at the build path properties.
After project creation + build in eclipse, the files .project and .classpath are created. Inside the project you should now see at least your sources inside java source folders - and maybe you are able to start the application.
For more information see also
https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2FgettingStarted%2Fqs-3.htm
https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-wizard-java-project.htm
Thanks everyone,
I did not found any .JAVA files in the source so I am sure that they did not pass me the complete source file!
Thanks
Sepide

Exporting project in eclipse only exporting .classpath and .project

I imported a git folder https://github.com/TeamLapen/Vampirism.git ((If you were wondering)). And so now I have it within my eclipse workspace, but not "really". Here's what I mean: The project shows up in the tree on the left of the eclipse window, but the folder itsself is NOT located in the /workspace/ like the other projects.
All I did in the code was change a few lines to fix a bug, as is highlighted below.
Anyways, when I go to export the file (File > Export > Jar), a few things happen:
In the box on the left, you see the project name is "Vampirismx". In the middle box, you see that the project is NOT AVAILABLE FOR EXPORT. In the right box, you see the only files "available" for export are the classpath and project files.
Can someone help me?
Tl;dr
I imported an eclipse project from git. When trying to export it, the project isn't showing up.
looking at the git repository, it does not provide eclipse project settings, and indicates only step by step instructions for intelliJ.
So when you imported it into eclipse, you have it on your workspace like a plain project, not a java one and that is why trying to export it as JAR does not shows up.
You must indicates that the project is a java project and it should work.
also, i'm not familiar with gradle, but seams there is a goal for settings things in eclipse : https://github.com/TeamLapen/Vampirism#setting-up-vampirism-in-another-environment

Including external jars permanently in NetBeans

I'm building a Java Swing Application. This project requires a jar file called JCalender. I've added this to Libraries folder and everything works fine on my computer in NetBeans. But when i open the same project in my friends NetBeans, it doesn't recognizes this library. I've to manually select the file placed inside the projects dist/lib folder. How to avoid this? please help!
But when i open the same project in my friends NetBeans, it doesn't
recognizes this library. I've to manually select the file placed
inside the projects dist/lib folder. How to avoid this?
You can't avoid this because it's not a problem actually. To compile and run a project you need to have access to the external libraries involved in the development, so if you open your NetBeans project in a different computer than yours you will definitely need to resolve the reference to the external libraries. There's no way for the IDE to do it automatically as far as I know.
Can't i give the relative path to the lib folder for that specific
library somewhere in project properties?
You could just give it a try. IMHO if the real goal is to share a project with other developers then I'd change the strategy. I'd create a Library (Tools -> Libraries) and tell my mates to create the very same library including the JCalendar JAR files in the library's classpath. I'd include this library in the project properties and finally I'd use a versioning tool like Git or SVN to share the project.
By doing this your mates still need a copy of the JAR file wrapped in a NetBeans Library, but the project properties won't point to a fixed/relative path looking for a JAR file but wil include a reference to a given Library. The Library itself will resolve the dependency to the JAR file. If you take a look to the project.properties file you'll see something like this:
javac.classpath=\
${file.reference.jcalendar-1.4.jar}
But if you as I've suggested then you'll see something like this:
javac.classpath=\
${libs.JCalendar.classpath}
Here libs.JCalendar.classpath will resolve the dependency so your mates can have the actual JAR file located in whatever folder they like and the project should compile just fine.
Another option is using Maven to manage the projects dependencies but honestly I'm not a Maven expert so I can't help you in this path.
You need to do a "clean and build" and your jar will be in the dist folder. It will include the external jars
You can read more about it here
I think your problem is due to you are providing absolute path of jar file.
while choosing jar on write side of filechooser there is option of
Relative path and Absolute path there you should click on Absolute path.
i am new to java , but anyway , i have faced the same problem and found a solution for my project
If you are in Netbeans , its would be very easy for you
Let you project name is ABC and all your dependent jar file is under the
the folder MyResourceCollection
now we need to permanently import all jars under this folder ,
So from Netbeans ,
right click on your project name
go to properties
go to library
in the library page , check the "libraries folder" label
you can find a browse button at the right side of the label
click browse and select the MyResourceCollection folder
a new window will come , just press Next-->Next--->Finish
all is done , now check yourself by moving the folder into different location

Where to get the .java files of a netbeans project?

As you might notice, I'm quite new to netbeans and programming in general.
I've been working on a small project (homework) and now I need the .java files from one of the packages. When I build the project, i get a .jar archive with all the classes. When I compile the package I need, I get a .jar archive of the .class files of this package (in the "build" folder of the project). However, I need a zip archive of the .java files of this package. I'm a little embarassed to ask, but where do I get these from?
Thanks,
Zhao Nan
From the Projects window (Window-->Projects) or Ctri-1
Navigate to the .java file you want, and right-click on it, and select Properties. The path to the file is shown under All Files.
To see the path to the project right-click on the name of the project (in the Projects window), select Properties, and the project folder is shown under Sources-->Project Folder
If your are on windows, usually if you let netbeans create all by it self it creates a directory called
NetbeansProjects
Under "documents"
There will be a folder list of all your projects. Under the project name that interest you, go in the "src" folder. All your java files should be there.
On Ubuntu 16.04 using NetBeans IDE 8.2, a folder called NetBeansProjects was created in my root directory, parallel to the netbeans-8.2 directory. I'm guessing that this was suggested at installation time and can be configured differently.

Import project (jar) into Eclipse

I got a .jar file which I need to import into Eclipse. However, I don't want to have the jar as a referenced library. I need the .jar to be included like a "normal" project, with packages(!) and .java files.
I tried to do the following:
New Java project -> Import -> General -> Archive File. In this case, when I place this jar also as a referenced library, it is imported but with .class files.
New Java Project -> Import -> General -> File System. Imports the .java files, but the packages are lost and are normal folders. Also, the files are somehow strange, because the "j" in the icon looks differently, and errors are not noticed (no underlining)
Importing "Existing Projects into Workspace" doesn't work at all, it says that there is no project. I also tried to import the jar as a zip after extracting it, this gives me the -java files, but it destroys the packages.
Does anyone know how to import this correctly?
I have managed it this way:
New Java Project -> Java settings -> Source -> Link source (Source folder). There I added my decompiled jar and it was imported correctly :)
You can also create a new Java Project and then do File -> Import -> General -> Archive File. This will save you a step of unzipping your jar and adding as a linked source folder.
You cannot import a jar that way, unless it has the source code packed in the jar. If you really need the source code, you'll have to find an archive somewhere. But of course, not everyone is willing to share his source...
I tried the below and it worked.
Create a New Java Project
Goto File > Import > General > Archive File
Select the required Archive file(.jar in this case) from your local system.
Select the project you created in Step 1 and click Ok
This will save you a step of unzipping your jar but if there are .class files, eclipse won't convert them to .java files. This has to be done seperately.
Below helps in all recent eclipse.
Please try below eclipse plugin to import jar as project :
Step 1) Eclipse Help > Eclipse Marketplace
Step 2) Install the plugin "Import Jar As Project"
Step 3) Restart Eclipse
Step 4) File->Import->Other->Jar without source
Step 5) Select a jar/war file and click finish
New project will be created from the jar
https://marketplace.eclipse.org/content/import-jar-project
Thank You.

Categories