0

I'm fresh to Java and cannot get this right.

I've got only a .java file from a Java study book, that represents a Java project. There seems to be no option to input such file from Netbeans interface, that would automatically compile corresponding class and enable project to run.

I've spend a long time to figure this out, copying files manually, changing the automatically created class names and packages, moving this around - but I don't find a solution.

If someone can help - this will be great.

Pawel

4
  • Have you tried this: 1) On you netbeans toolbar click on "File" 2) Got to "New Project" (OR ctr+shift+N) 3) JAVA 4) "Java project with existing source" 5) browse to your project folder. Commented Oct 26, 2014 at 20:04
  • Hi Payam, thank you for replying. I tried this, but when I run I get <no main classess found> . In the Files/Build/Classess folder window there is no .class file. Commented Oct 26, 2014 at 20:51
  • Hi :) ... ok listen, "every" java project needs to have a main class which is the class that includes the main method which happens to be public static void main(String[] args) {} in java language. I suspect that this file is missing this particular method. Hence I recommend you to open the java file with Notepad++. With this you can look at the source and understand it. If again you face some issues edit your question and add the source code. Commented Oct 26, 2014 at 21:11
  • Hi, many thanks Payam for your response. I was not available anymore, but kept digging anyway later. Seems it's ok now, code was fine so it was more about the NetBeans settings - thanks again anyways! Commented Oct 28, 2014 at 20:20

2 Answers 2

2

It seems the issue was following. .java file should be placed in "src" directory within the Project folder, rather than straight in the Project folder.

So if say "Project" is one's destination folder, then one can:

  • choose from menu: New Project-Java-Java project from existing resources - indicate path to the ...\Project folder
  • the next step is to choose "Source Packages Folders" and here the path should lead to ...\Project\src .If the file .java is correctly placed there, the creator will indicate below that .java file is included to the project

If the code is right after finishing the creator and compiling it we get a compiled class Project.class and we can run it :)

Not sure if there is some work around to this in NetBeans, as it's not super intuitive, but I might not have found a better option.

Sign up to request clarification or add additional context in comments.

Comments

0

I too was looking for File > "Import File", because there is an "Import Project" option. It appears dragging and dropping the java file into Source Package is just as easy. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.