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

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.

Related

maven does not include fxml file

I try to create a maven project of a java program, which includes two java classes and a fxml file, which are all located in the same directory (src/main/java/package).
When i install the project with maven it does not copy the fxml file into the .jar file so that the program does not work any more. A few hours ago I basically created an equivalent project and everything worked fine.
How can I fix that?
The Maven convention is that Java files go in src/main/java. Any non-Java files go in src/main/resources.
The Eclipse emulation of Maven does not make this distinction. Both directories are source folders which is incorrect but "good enough" to handle correct Maven projects.
So, move your file to the correct location.

Moving from NetBeans to eclipse, can't seem to find generated java files

I have been developing in NetBeans, I am exploring changing over to eclipse.
We have a set of directories for the modules in our project; we have scripts that check things out of Subversion and do other things with that directory tree, and we have NetBeans access the sources, etc., from that directory tree.
All our modules are built, etc., with Maven. All of this works fine from within NetBeans.
I have successfully imported all the projects into eclipse (File / Import / Maven), but evidently something is different in the handling of "generated sources". We have some castor-generated files in one module, and jaxb-generated files in another. The generated files in both cases are not found by the compiler, and therefore these modules have compile errors.
Maven is configured to generate the Java classes which cannot be found; maven clean deletes them and maven compiler:compile puts them back. But in eclipse those java files cannot be found for compiling other classes, but in NetBeans they can.
I tried deleting the generated java files, then rebuilding in eclipse; the java files were regenerated in generated-sources, but still cannot be found by the compiler when it comes time to compile (or syntax-highlight) my code.
It sort of looks like a classpath issue, but we don't set the classpath in NetBeans for a maven project. How should I configure things in eclipse so the generated class files are found?
In Eclipse in the Package Explorer right click the project folder which contains the missing files. Goto "Build Path >" then "Configure Build Path...". Properties for your project folder will open.
Click on the "Source" tab. Then click on the "Add Folder..." on the left. A source folder selector box opens, here select your folder which contains the auto generated sources. Normally it will be in the target directory. Then press ok. If this will not work, try one directory deeper or less deep.
If there is no target directory, build the project folder with maven on a shell.
The generated-sources directory will be stored in the .classpath file in your project folder.
HTH.

Creating a source package folder in a CounterClockWise project programmatically

I have an existing java project and in that project there is a procedure that should programmatically create packages with source files inside them. It uses the standard File.mkdir() method to create all the unexisting directories for the package and then creates and writes the source files in there.
All works fine except that only the top folder created for a package path is marked by Eclipse as a package. The lower level folders remain just folders. For example, if I create a directory structure for package "org.prj.hey.this.is.cool", where "org.prj" is the existing path for my main project package, it then creates the rest of the path "/hey/this/is/cool" and only "hey" becomes an Eclipse package. I have found no way to make Eclipse recognize the "this", "is" and "cool" folders as packages. I haven't found any clues on this in the .project and .classpath files either..
So how do I make the whole branch of created folders be recognized by Eclipse as packages?
UPDATE:
(screenshot)
Found out that the issue is due to the file extension (see the picture). Is there any way to make Eclipse recognize .clj files as source files?
Problem exists in your current eclipse workspace buildpath configuration. Perform rightclick on your project name, then "Build path->configure build path..." and add newly created dirs to your current build path in SOURCE tab.

Running my java project from a Jar

I have a Java project that I'm working on in Eclipse. I have all my code in a src. Eclipse automatically compiles my .java files and stores the .class files in a directory called tmp.
Earlier, I was suing Ant to run my project. My ant script would would compile my Java code, and Jar all the .class files into a .jar and store it into a jar directory. In this jar directory I have some other files e.g. settings.cfg and data.lst. My application needs these files to run but they should not be included in the Jar. They will be deployed along with my JAR and should reside in the same directory. Currently while developing, I have modified and customised my settings and properties files to contain additional information. I don't want these files replaced every time I have a new build as I would like the data to persist across builds. I'm just looking to get the built JAR into the jar directory and execute that. The rest of the files stay the same.
How can I configure my Eclipse so that it always compiles my code, JARs it to the jar directory and executes that JAR. That way, my "extra files" are always in the same place as the JAR.
I'm having a lot of trouble figuring out how to accomplish this.
If you need this feature for fast running/debuging, create new Run Configuration and in the Arguments tab, Working Directory specify the "jar" directory.
The answer was found on another SO post. It was about creating a new "Run Configuration", removing the default classpath entries and adding a the folder containing the JAR i.e. the jar directory and also the JAR file itself.
Here: https://stackoverflow.com/a/1732316/304151
I also had to modify the build configuration a bit. For automatic builds, it used the Java Builder to compile all the .java files into .class files and store it in the tmp directory. I used a custom Ant task to package all the .class files from the tmp directory into a JAR and store it in the jar directory. This is the file that Eclipse executes.
In your project, right click Properties, in "Java build path" menu you can set "default output directory" in the Source tab and make it point to jar directory:

Eclipse & JAR Hell

EDIT: I appreciate the suggestions for Ivy or Maven, but this is just not an option for me at this time. I do not have the authority to use those tools. I am simply looking for a way to get my referenced .classpath JARs into a folder inside my project.
I have created a project that uses about 50 external JAR files that I referenced from other projects inside the same workspace.
Thus, my project's directory strucure looks like:
MyProject
src/
test/
Referenced Libraries/
... 50+ JARs
lib/
My project compiles and runs beautifully inside Eclipse. But now I need to add a buildscript so other developers can pull the project down from SVN and run it standalone. To do that, I'd like to place all the JARs that are currently in Eclipse's in-house directory Referenced Libraries and copy them into my project's lib directory which I will JAR-up with the final distribution.
I'm in Package Explorer, and have tried to just copy + paste the files from Referenced Libraries to lib/ and no dice. I get the following Eclipse error:
Cannot paste the clipboard contents into the selected elements.
Anybody have any idea how I can force this copy operation to work? If I right-click any JAR inside Referenced Libraries I see an Eclipse option called Migrate JAR file, but I'm afraid that would cut-n-paste the JARs from their current location to the new lib/ directory. This isn't feasible because there are many other projects that need these JAR files exactly where they are.
Thanks for any insight here!
Have you considered Maven? It's an exceptional tool for situations like this. For file operations it's best to use Navigator view.
I don't find another way to go but to copy yourself the jars into your lib folder, add the references to your lib files (not to external jars on your machine) and upload it to SVN.
EDIT to clarify:
Remove all references from your build path. Now you can't compile the project.
Copy every jar file you need to your project's lib folder.
Go again to build path and add the references to your jars (the ones on lib) one by one. Use the button that says "Add JARs...", not the one that says "external JARs".
Compile, and if everything is fine,
Upload the whole project to SVN.

Categories