I've been working on a Processing project for a while, and now want to move it into Eclipse. I've installed Proclipse with my Eclipse environment.
I've a lot of files with the extension of ".pde". However the Proclipse files all ends with ".java". And there's a lot of dependency issues with all the pde files. How should I convert my project?
===============
Thanks everyone! There doesn't seem to be a one-button solution, I refactored all the code following an approach similar to George's answer. Plus changing all the file extensions from ".pde" to ".java".
Check this link http://www.learningprocessing.com/tutorials/processing-in-eclipse/ here you can find a more detail explanation of everything concerning this topic.
The most important thing to know when moving from the Processing IDE to another one like Eclipse, is that in Processing all classes are treated as inner classes, they are classes inside of the larger PApplet.
First you need to import the Processing library inside you Eclipse project, then you have 2 ways to make you code work.
You can extend from PApplet in your main class and add all you Processing code there, including all your other clases like inner clases.
Or you could work those clases separately by calling the same instance of PApplet every time you want to accede Processing stuff.
Jose's advice is pretty good. Proclipsing already makes creating a Processing project easy.
The easiest (but not cleanest way to get your Processing code running in eclipse would be taking these steps:
Copy the code from the main tab onto the Proclipsing generated class which extends PApplet(removing the default/existing empty setup() and draw() functions) but still within class' scope ({})
Make Processing functions from the pasted code(setup/draw/keyPressed/keyReleased/mousePressed/etc.) public (e.g. public void setup(){//etc. instead of void setup(){//etc.)
Paste the rest of the code from other tabs into the same java class generated by Proclipsing
Append an 'f'(explicit float flag) to float type values(e.g. 3.0 becomes 3.0f)
If you're using libraries Proclipsing should help with that: right click the project and go to the Proclipsing project properties. If you've setup the correct path to Processing's folder(e.g. Documents/Processing), the extra libraries will be there so you just need to tick/enable them. Otherwise you will need to manually copy the .jar file of each library and paste into your project's lib folder, then right click the .jar files in eclipse and select Build Path > Add to Build Path
Update
Here is a slightly simpler approach using Processing's Export Application feature.
I will explain this workflow using the Daniel Shiffman's Boids example from Examples > Topics > Simulate > Flocking since it has multiple tabs and classes.
Export the application. This will generate an application folder including a source folder with Flocking.java (as I mentioned above, Processing actually bundles all your tabs into a single .java class)
Create a new Proclipsing project
Paste the code from the Processing generated class into the Proclipsing generated class after the package statement.(a package is a folder can hold multiple classes, so use this to keep things tidy/nicely organized in folders based on what the classes do)
Update the static main method at the bottom to use the fully qualified class name (so the class name prefixed by the package name)
At this point hopefully most of the errors should have disappeared. Try to run your code as a Java Application now.
The problem is at this point you have one massive class which is still hard to maintain, probably the reason you're moving to eclipse in the 1st place. Now would be the time to refactor(restructure your code) and luckily eclipse has some great tools for that.
If you see repetitive code, that's a great candidate for a function. You can try selecting that code , right clicking then choosing Refactor > Extract Method. The values that change in the repeated code can be extracted as arguments/parameters.
Inner classes should move to new .java files and if you use Processing specific functionalities in those classes you've got multiple options:
Passing the PApplet as an argument to those classes (like the Jose's Processing in Eclipse article link suggests)
Using PApplet's static methods(e.g. PApplet.map() instead of map())
Implementing PConstants in a class
Passing the renderer(PGraphics) if a class only deals with drawing in Processing
Most importantly though you should familiarize yourself a little bit with Java (compiling a HelloWorld program from scratch which will shine a light on Processing's inner classes) and especially some OOP concepts(composition, inheritance and perhaps a few basic design patterns (such as Visitor or MVC) in the future. This of course, if you're new to these concepts :)
Update the simplified updated instructions for Proclipsing are now available as a video here. The first two minutes illustrate the basic process and the rest covers some of the refactoring concepts mentioned above.
Related
I'm trying to understand the file structure in Netbeans.
For example: I want to create a new class. I do so by right clicking the navigation bar, and get prompted to name my new class. A warning appears with the words "It is highly recommended that you do not place Java classes in the default package"
So,
What does go in the "default package"?
What goes in the Test Packages and Test Libraries folders?
If I have some text files or some such thing for my program to read, where should they go?
I'm taking some online courses on Java, but these sort of nuances aren't covered in the classes. I want to start doing it right, right now, so I don't have to untangle all of my files later on down the road.
You should refresh your understanding by reading the tutorial.
The default package is a package that gets created for your project. It's OK to organize your files under the default package, but if your work is somewhat serious, you're going to want to place them under a named (and therefore non-default) package, like com.myorganization.myproject as per the tutorial. NetBeans will also allow you to refactor (rename) an existing package. Left click, hit F2 and supply a new name.
Test packages and libraries used to test your project go in the Test Packages and Test Libraries directories. It sounds like you're a ways off from testing with frameworks like JUnit, however, so you needn't concern yourself with those things just yet.
If you have arbitrary data files, you can really put them wherever you can find them later. If you're working with Android, for example, you'd have a /res directory just under your project root with resources like images, icons, data files, etc. You can create your own resources directory, or you can be lazy and dump them directly in the project root. Wherever you put them, you have to make sure you call them correctly using absolute or relative paths.
If you're using online courses, especially if you're paying for them, use the resources they provide, like live tutors or their forums. This kind of fundamental/tutorial help is a bit below the threshold for Stack Overflow.
I am planning to do all the exercises from a introduction to java textbook and was wondering how to save each program individually in the IDE NetBeans. Is making a Project for each exercises necessary. I would like to be able to put these problems in order by chapter. Having them in Netbeans would be a great help down the road but if its impossible I was thinking I could always write the program in Netbeans and just save the java and class file in a separate folder.
Thanks for the quick responses I'll be gone for a while to reply to anymore responses.
It is not a necessity to create a project for each exercise. I'm assuming that your exercises are most likely to be single file programs. In that case, you can just use shift + F6 to run the current open file.
You can create a single project, and add different packages/folders in that project. Then you can use your main class to call some sort of class in each package, to start every exercise.
When I worked on tens of exercises while completing AP Course, I always created a new project for all of them. I suggest doing so for the following reasons:
It takes 20s max to create a new project.
It makes your projects nicely organized.
You don't need to change the main method every time you want to run an old project.
It is not very easy to save or load .java file in NetBeans
Making a netbeans project is required, except if these exercices are quite simple and only exist out of one class. Then you can combine multiple excercises in one project as seperate classes.
If you are learning Object Oriented Programming then you will need multiple classes for one exercise I suppose. Then I can recommend you to use 'Project Groups' to arrange exercises by chapter (each chapter is a seperate Project Group). You can find the project groups menu under the file-tab.
I know how to create a jar file using Eclipse.
I was trying to create a share library so that I can avoid redundant source code. I have figured out that a jar should be :-
independent
should not make call to external class attributes(properties)/methods except the standard library imports.
The resources should be given as a parameter to jar file to perform a action.
Should work as a independent entity.
I tried to well organised my code in different packages also added MANIFEST.MF file.
This is first time I'm trying for data abstraction.
I would like to request suggestions/instructions as per the programmer point of view, what are the criteria that jar code should have ?
Is it good idea that my jar is or depend on another jar (viz java mail api jar) ?
Thanks in advance.
As you've tagged this with Android, I assume that Android is the intended use case.
The easiest way to share your code between several projects is probably to create a library project, this way you can keep the source code at hand too (less convenient to attach source to the jar every time you use it).
For Example, i just have a bunch of classes sitting out there for my game. Some are drawable, nondrawable, animated sprites, and more.
I just want to know if I right-click my package and add a folder.. drop some classes into it, will it disable my program? I know in XNA it worked like that because you had to give the path. I am unsure in android.
Thanks guys and GALS
*Edit (included GALS)
No, adding folders and new classes will not affect your program (unless you're doing some processing that depends on your class hierarchy structure staying constant, which is not very common). However, if you move existing classes to different folders, you will also need to change the package statement in each source code file that you moved, as well as all references to these classes.
If you want to reorganize your class files, the refactoring capabilities in Eclipse will help you with this; you can move a class using the refactoring tools, and Eclipse will update all references automatically.
Are there any open source tools that automate the functionality of finding the number of usages of a Java API? I can figure out this information for one class at a time in my IDE. I want to use this information to create a rudimentary report on the speed of adoption of a particular library. I would create a daily report on the number of usages of dozens of classes, and I would report on several code bases.
I'd go with one of those tools for analyzing dependencies in Java code. Let it work on your source tree, a package or a single class and see if you can export the results to XML or something like that. I've used Dependency Finder in a project about two years ago and I think it should do what you want. Not sure about the export to XML, though.
In Eclipse you can right click on a method name or class and go to the References menu and from there you can choose the scope of where you want to search for classes that reference that item.
Is that what you need?
I'm going to try Macker. Its style is to report references to configured classes as errors, but that's fine. It can be run from an automated build. Thanks Robert.