简体   繁体   中英

import .java file to Java project in Netbeans

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

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.

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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM