How to import existing project into Workplace in Eclipse? - java

I am trying to follow Eclipse instructions to create a Hello World SWT application. I have the following instruction:
Import the SWT project from the main
menu via File > Import..., and select
Existing Projects into Workspace.
Specify the archive file you
downloaded and click Finish. This will
create the org.eclipse.swt project
which we will need to compile and run
the application.
I have troubles with that. In the "File" menu I see "Import...". When I click the "Import...", I do not see "Existing Project into Workspace". Instead of that I see "Select an import source:" after which I see a text field. After that I see a field with the following folders: General, CVS, Run/Debug, Tasks, Team, XML.
Can anybody help me with that, pleas?

You need to expand General.

If you expand the 'General' node (folder) you will see 'Existing projects into workspace' as an option. Select that and click on Next.

Eclipse has the wonderful search functionality on most of its important screens. Even if you don't know where exactly it is, you can type it and it appears. In this case type "Existing" into the text field above the list and you'll see what you are looking for.

Related

Eclipse doesns't show project explorer properly

I'm using eclipse neon. I have created a maven project and create a package com.prueba.account and then I have created many packages inside.
But eclipse shows me all packages as an independent project and without the full path like in the image. Notice that checking package is inside com.prueba.account
Just Click on the Drop Down in Project explorer. All you need is to change Package presentation from Hierarchical to Flat.
Hope it helps !!!!
First of all, welcome to Stack Overflow Gary.
Then to extend on Adyas Answer:
In Eclipse there are two ways to display the package-structure.
Hierarchical :
And Flat:
I personally find the Hierarchical view way more convenient, for when you're working on a bigger project, you often get really long package names which, when in Flat view, might clutter the whole window.
But in the end, it's up to your personal taste.
The way to change between this two modes is to click on the down arrow icon at the top of the Project Explorer and under Package Presentation you can choose between the two.

Eclipse right click new project preferences

Well, honestly, it is a simple question I can't find on eclipse nor google.
I am a lazy dev and want to add the Maven Projectoption to my [right click]->New->(Maven Project). But can't find an option in the preferences. Every Javaproject I create is a maven project (DM FTW, YEA!)
In PHPStorm I can simply add/edit an entry in a config section and I am done. It gets added to any "New" context.
Can I do something like that in eclipse? Add completely new "New..." entries to create a templated new file type and (the original topic) can I add another menu entry without writing a plugin?
Thank you in advance!
open eclipse, then go to Window menu, select Customize perspective...
a windows appears. it has for tabs.
Tool bar visiblity
Menu visiblity
Command Groups Availablity
Shortcuts
select Menu visiblity tab, it will shows all menus with tree view.
then expand tree view of File then do same for the New which is sub tree of File.
now select All of those project types that you want, then click Ok.
The concept is:
new means creating a bare project begining from zero,
adding means import some project that you/other have/has started...
in eclipse import is the menu you need to click to, then maven, then select the proj option the best fits you...

How to add project to Create Project Wizard in Eclipse

In Eclipse while creating new project, the following window opens (consider the area surrounded by red lines in the image).
From that we can select project as Java Project or as per our requirement.
Now my question is, is it possible to add Custom Java Project as a project template in select Project Wizard ? If yes, how?
I want to create (please look the area surrounded by black lines in the image) a project having the name IoTSuiteSpecification as a default Project template in Select Project Wizard with mentioned four files and package.
For example, while creating new project, IoTSuiteSpecification is there in Select Project Wizard. Let me know if you need more clarity.
As you did not provide detail about what function you want to implement. This answer will just focus on how to create a new project wizard, but not the functionality details.
In short: you need to write a plugin and install that on every Eclipse you want to have this function.
I would like to keep this answer short, so the following content assumes you have basic knowledge about Eclipse Plugin Development, and have already created a plugin project. If not, please refer to tutorials such as Your First Plugin or Google "Eclipse Plug-in Tutorial".
Step 1: Create an extension for your project wizard
Go to plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards, choose the "New File Wizard" template, click next.
Name your Classes properly. I will call everything NewWizard. So the wizard class is NewWizard, and the wizard page class is NewWizardPage, etc. Do not care about the "File Extension" and "Initial File Name", we won't need them.
Click Finish
Step 2: Implement the classes
After the previous step, you will have a package containing the wizard classes you just created. It should have two classes NewWizard and NewWizardPage.
First, you need to customize NewWizardPage to provide controls for your user to specify information such as Project name, etc. Refer to org.eclipse.ui.dialogs.WizardNewProjectCreationPage for an example of how to create a new Project Wizard page.
When you gather information from user, you should do some setup of your new project. Open class NewWizard, and find the function performFinish. In this function you should create your new project and setup it such as adding project natures. org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard is the eclipse wizard for creating a new general project. It provides a good reference for how to do these. If you have no idea, read or just copy their code.
Step 3
That's it! Enjoy your new project wizard!
Examples
As an example, you can look at my project https://github.com/harperjiang/TeXDojo. This is a plugin I wrote for Eclipse to edit and compile latex files. It contains a complete project wizard implementation in the package LaTeXEditorPlugin/src/hao.tex.dojo.latexeditor.wizards

View Package Dependencies in Eclipse

Is there any way to view package dependencies in Eclipse? I seem to remember a long time ago that it was possible. I have a packageX and want to see what packages refer to it. Ie packageY references it, but not packageZ.
There seem to be some outdated plugins out there, for example Java Dependency Viewer, but the comments for the plugin say 'don't bother'.
If you mean a java package, there is a possibility: You right-click the package in the project explorer, select References → Workspace and get ... a list of almost no results.
Then you go into the search menu (the small triangle ▿ at the top right border of the search view), select "filters" and uncheck the "imports" box. Then all references to your package within your workspace should appear in the view.

Netbeans - Error: Could not find or load main class

So I'm making a java application in Neatbeans 7.4, been working at it for a while, everything was fine, running the project worked fine, but now when I hit run project, I get the error
Error: Could not find or load main class phleveledit.MainWindow
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I can't think of what I did right before this started happening, so I don't know what I should change.. The code doesn't appear to have any errors. Here's a screenshot of the IDE+project folder
Image (http://puu.sh/5ldYB) :
Any ideas?
Edit: Unfortunately I happened to fix this problem by removing some code, which probably had some errors Netbeans couldn't detect, but I don't know what was exactly wrong so can't vote on a correct answer.
Right click on your Project in the project explorer
Click on properties
Click on Run
Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
Click OK.
Clean an build your project
Run Project :)
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Just close the Netbeans. Go to C:\Users\YOUR_PC_NAME\AppData\Local\Netbeans and delete the Cache folder. The open the Netbeans again and run the project.
It works like magic for me.
(AppData folder might be hidden probably, if so, you need to make it appear in Folder Options).
You can :
RightClick on project node and go to Set configuration
Select the main class for your application.
Then clean and build.
Even if the above steps don't work for you then then delete the Netbeans cache by deleting the (index) folder
User\.netbeans\SOME_NUMBER_reflecting_your_version\var\cache\index\
Sometimes due to out of memory space error, NetBeans does not load or find main class.
If you have tried setting the properties and still it is not working then try
Select the project from the project explorer
Click on Run in the Menu Bar
Click on Compile
It worked for me.
This condition happens to me every 6-months or so. I think it happens when closing NetBeans under very low memory conditions. I discovered that it could be easily corrected by (1) Rename your project, including its folder name using right-click on project explorer's project name---I put a simple suffix on the original name ("_damaged"). (2) Try BUILD. If that is successful, which it is for me, give three cheers. (3) Repeat step (1) to restore the original project name. BUILD and RUN should start without trouble.
I guess that the 'rename the project and folder' process causes a special rediscovery of the applications main location.
Try to rename the package name and the class/jframe names... The clean and build the application.
Right Click on the package name
Go to Refactor
Select Rename
Give it a meaningful name, preferably all in small letters
Click on Refactor
Do the same for the class/jframe names.
Last Select Run from Menu
7.Select Clean and build main project
That should do it!!! All best
I had the same issue once. The problem was not in the code. The cause was... renaming the project folder to some other non supporting name. My project name was "MobStick" and I renamed it to "MobStick - May 26, 2014 04:00PM". Renaming it back to normal solved my problem.
I have run into this error a couple of times as well and for me the above solutions did not work. What does seem to work is going to the Project Properties, and under Compiling toggling Compile on Save.
Using NetBeans 8.1, I got the dread
Error: Could not find or load main class
from carelessly leaving an empty line in the Project Properties > Run > VM Options field. Until you click in the field, you may not see the caret flashing out of place. Remove the empty line to restore equanimity.
I just ran into this problem. I was running my source from the command line and kept getting the same error. It turns out that I needed to remove the package name from my source code and then the command line compiler was happy.
The solutions above didn't work for me so maybe this will work for someone else with a similar problem.
I had the same problem, I had the package and class named the same. I renamed the class, then clean and build. Then I set the main class in the "run" under the properties of the project. I works now.
I found the following steps useful:
Right-click on the project in the left toolbar.
Hover over the 'Set Configuration' item.
Click on 'Customize...'
Click on 'Browse...' by the 'Main Class:' item.
Select the correct class.
Click 'Select Main Class'.
Click 'OK'.
My problem was that, apparently, my package name was being listed twice. Selecting the class using the dialog changed 'aclass.MainClass' to just 'MainClass'.
Hope this helps,
-HewwoCraziness
Edit: This is expanding on Mary Martinez's answer.
You can solve it in these steps
Right-click on the project in the left toolbar.
Click on properties.
Click on Run
Click the browse button on the right side.(select your main class)
Click ok
Possible Fixes:
Fix 1
Go to project properties (right click on the folder of your project in netbeans)
On left tab where it shows the categories, click on the "Run" selection
Then click on Browse to find the Main class you use on your project
Fix 2
Go to C:\Users\name\AppData\Local\Netbeans
delete the Cache folder.
Rebuild and Run
Fix 3
Download most recent version of Netbeans
Fix 4
Download most recent version of JDK and configure Netbeans to use that
I had the same problem for 3,4 days. On my PC my Jar file snapshot would give me this error while on my laptop it would work fine, I tried all the tricks shown above and on other forums like deleting cache, selecting main project file, etc, but somehow I was sure the reason it cannot find the main class when I would execute the JAR file was may be due to classpath issue in maven configuration, and I was right and I fixed it using following steps:
Right-click on the project, and go to the properties
Inside the properties go to Actions
On the right side in Actions select "Run Project" and you will see properties below
Inside "Set Properties" make sure exec.args=classpath %classpath "package_name"
In my case, the package name was accompanied by the main class. So my main class was Login while the package name was com.mycompany.islamic_center_app1, When I checked the entry was
com.mycompany.islamic_center_app1.Login
All I did was remove ".Login" from com.mycompany.islamic_center_app1 and it was fixed, no more errors.
close netbeans.
open netbeans again.
choose new project>>java application.
click next.
deselect create main class.
now make the application
clean build run
For more reference watch this video
try this it work out for me perfectly
go to project and right click on your java file at the right corner,
go to properties,
go to run,
go to browse, and then
select Main class.
now you can run your program again.
I had the same problem and I moved the project to a location where the path had no none-english letter and that fixed the problem
if you are on window os, then try to start NetBeans via administrative mode. right click on NetBeans icon and "Run as Administrative".
If none of the above works (Setting Main class, Clean and Build, deleting the cache) and you have a Maven project, try:
mvn clean install
on the command line.
Had the same problem here. Usually Clean and Build solves much of the problem. It happened to be caused by a wrongly installed plugin.
I faced the similar issue with Netbeans 10 and JDK 1.8.
I was not able to choose the right class to launch the project
When I compile or run the project, it shows me the Class name as "initializing view, please wait ...", I could not select the class name.
The issue was resolved with the NetBeans11.3, I am able to choose the correct Class file without any other changes, and the project is launched without any issues.
I had the same issue but none of this thread's solutions worked for me. Finally, it was OneDrive that caused the issue (for once more). So, I simply moved the NetBeansProjects folder from Documents which is synced with OneDrive, to C:\Users\yourName\AppData\Local\NetBeans (selected this path as there is already a NetBeans folder) and that was it, case closed.
If you also have NetBeansProjects to a OneDrive syncing folder it is worth trying this solution, just be sure that the path you will select is not synced with OneDrive. Also, remember to close Netbeans before making the folder change and after you move the folder to the new path you need just to open Netbeans again, go to file menu/open project and select your project from the new path.

Categories