Creating a source package folder in a CounterClockWise project programmatically - java

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.

Related

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.

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.

Can I refer to a Java source path using a variable in Eclipse

Background
I'm using an Eclipse 4.2 (Juno) release to build a plugin for a Java application. The source code and classes for my plugin all reside within the project workspace. The application jar and its source code are, for various reasons maintained outside of the eclipse workspace and the application jar is produced by another build mechanism.
This isn't a problem as I have referenced the application jar file in my project using drag and drop and the 'Link to files' option specifying it 'Create link locations relative to: MYDEV', where MYDEV is a Linked Resource Variable I have created for each Eclipse installation. This lets me use the same eclipse project on multiple machines where the path to the application jar varies, but is always the same relative to MYDEV.
However, I cannot find a way to associate the application source code with this jar unless I use an absolute path. I only want access to the application source for debugging purposes.
Question
In Eclipse, how do I attach java source to a referenced jar in a way that allows a project to be used on multiple installations where the referenced source code has been relocated?
If the source is outside the proyect, then there's no way to access it without an absolute path.
The best solution is using a symlink inside the eclipse project directory to the actual source folder; eclipse won't notice the source is outside the project directory and everything will work fine, without having to relocate the source.
This is the only way I was able to do what you are suggesting (do not know if there are better ways).
Package a JAR file that contains the source code of the JAR file. Place it inside your project in a folder (you do not need to add it to your class path)
In the eclipse project right click on the JAR file and go to "properties" and then to "Java Source Attachment" From there select "Workspace" button and pick the jar file with the source code we added from the above step.
So the source attachment path will always be relative to the project. That way if you share the project via SVN, GIT or whatever, the source will always be available and it'll work if the user is running eclipse on Windows or Linux.
I've had a similar problem to you where absolute paths were a problem for people using different OS and not even using mapped drives via Samba helped that much.
Hope this helps.
The way I have solved this problem is to use a use defined library in eclipse. Here the steps that you can use to solver this problem.
Create a simple project in eclipse in the directory that contains the jars and the source code files.
Define a java user library add the jars to the user library and for each jar in the library specify the location of the source. If the source files are in a project that is in the workspace then the path will be relative to the workspace folder.
Export the user library as an .xml file
When another use wants to setup an eclipse workspace with the same setting as yours they will do two things.
Import the project that contains the jars and the sources into their workspace.
Import the user library into their workpsace.

What's in an Eclipse .classpath/.project file?

We recently had an issue with an Eclipse project for one of our team members. Tomcat was not deploying JARs of the application.
We eventually noticed the .classpath Eclipse file was not the same as for the team members where the project was OK. We replaced the .classpath file with one from a project that was OK and the Tomcat deploy was complete.
Just out of curiosity and to know at what to look in the future if something is wrong, what is inside the .classpath and .project files. What can I add in there, what does it all mean?
Eclipse is a runtime environment for plugins. Virtually everything you see in Eclipse is the result of plugins installed on Eclipse, rather than Eclipse itself.
The .project file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view. What's the project's name? what other projects in the workspace does it refer to? What are the builders that are used in order to build the project? (remember, the concept of "build" doesn't pertain specifically to Java projects, but also to other types of projects)
The .classpath file is maintained by Eclipse's JDT feature (feature = set of plugins). JDT holds multiple such "meta" files in the project (see the .settings directory inside the project); the .classpath file is just one of them. Specifically, the .classpath file contains information that the JDT feature needs in order to properly compile the project: the project's source folders (that is, what to compile); the output folders (where to compile to); and classpath entries (such as other projects in the workspace, arbitrary JAR files on the file system, and so forth).
Blindly copying such files from one machine to another may be risky. For example, if arbitrary JAR files are placed on the classpath (that is, JAR files that are located outside the workspace and are referred-to by absolute path naming), the .classpath file is rendered non-portable and must be modified in order to be portable. There are certain best practices that can be followed to guarantee .classpath file portability.
.project
When a project is created in the workspace, a project description file is automatically generated that describes the project. The sole purpose of this file is to make the project self-describing, so that a project that is zipped up or released to a server can be correctly recreated in another workspace.
.classpath
Classpath specifies which Java source files and resource files in a project are considered by the Java builder and specifies how to find types outside of the project. The Java builder compiles the Java source files into the output folder and also copies the resources into it.
Complete reference is not available for the mentioned files, as they are extensible by various plug-ins.
Basically, .project files store project-settings, such as builder and project nature settings, while .classpath files define the classpath to use during running. The classpath files contains src and target entries that correspond with folders in the project; the con entries are used to describe some kind of "virtual" entries, such as the JVM libs or in case of eclipse plug-ins dependencies (normal Java project dependencies are displayed differently, using a special src entry).
This eclipse documentation has details on the markups in .project file: The project description file
It describes the .project file as:
When a project is created in the workspace, a project description file is automatically generated that describes the project. The purpose of this file is to make the project self-describing, so that a project that is zipped up or released to a server can be correctly recreated in another workspace. This file is always called ".project"

how can i use referenced libraries

Hi I made one jar file with 3 classes.They work fine they are supporting file for getting HXM data.Now when i made jar i want to use it in my next project.I imported it and now it is in referenced libraries.But i can not find how can i use the libraries. in old project from i take the 3 .class file they have the paths: sk.csabi.hxm.*
but now how can i import and use them?
thanks
Your question isn't very clear but it seems like you're asking how to add the JAR to your project classpath in Eclipse.
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.

Categories