How can I import / use StdDraw in java eclipse? - java

I have found 3 questions similar to mine and none of them helped me at all (some of them even had some down votes, the answers I mean).
I wanted do an old homework for learning purposes and it's saying that we can use StdDraw function of java. (What we are supposed to do by the way is drawing the pythagoras-tree!)
But I haven't found a way to import that in java, either it was outdated or it was explained very complicated. : /

"StdDraw" is not part of the Sun/Oracle Java distribution (and never was), which is why you're unable to import it. I'm guessing that you're referring to a Java class that was developed at Princeton University for educational purposes as part of their stdlib.jar library:
http://introcs.cs.princeton.edu/java/stdlib/
Download that jar to your computer. Assuming that you've already created a project in Eclipse:
Right click "Project" and select "Properties"
Select "Java Build Path"
Select "Libraries" tab
Click "Add external JARs..." and select the jar you just downloaded
You should now be able to import StdDraw into your app.

1) Right click on (default package)
2) Build path, configure build path
3) libraries tab
4) Click on Class path
5) Add External JARS.
This worked for me. Other people might say to click on "Add external class folder" if this doesn't work click "add external jars".

Related

JavaFX Eclipse suggestion to import not present

I am just starting with JavaFX and for some reason, Eclipse does not suggest to import JavaFX stuff so I have to type it in manually. Example: javafx.scene.Group I typed in Group as a type and it suggested other things such as javax.swing.GroupLayout.Group
image of suggestions
I'm not exactly sure, but I think maybe the fact that the JavaFX library is under Modulepath instead of Classpath has to do with it, but it only works if it is under Modulepath.
Help would be greatly appreciated, thanks!
I'm rewriting this answer, as #kleopatra pointed out it was inexact
For suggestions to work, you need to have JavaFX on your project's build path.
If you've created a plain Java project in Eclipse, with a module-info.java at it's source path root, then you need to add all the required jars to the module path:
JavaFX SDK should already be installed on your system, or download it from Gluon and unzip it
Right-click your Java project, got to Build Path -> Configure Build Path...
Go to Libraries tab, point to the Modulepath section
Click [Add External JARs...] button, pick all the jars from JavaFX SDK, hit [Apply and close]
Then suggestions should work as expected, and imports will be automatically inserted at the top of your java files, but they will appear in error the first time you import anything from a given library module, as this module must also be required in your module-info.java. You can do that automatically with a quick fix ("Add 'requires javafx.something' to module-info.java") when hovering the import.
Now there's a more straightforward way to create a JavaFX modular project in Eclipse, using Maven:
Create a new Maven Project
Check and pass the first wizard screen
Select archetype org.openjfx:javafx-archetype-fxml
On the next screen, you can select the JavaFX version of your choice (currently 13 by default)
After the wizard terminates, you've got a nice little project already setup with an application window and two FXML sample displays. You can start from there to build your own project.

How to import one Eclipse project as a library into another?

I would like to use one of my eclipse projects in another one. Is there a 'smooth' way to do that, without having to export one as a jar file and importing it into another? Especially since I work on both project simultaneously, I would like the latest changes from the imported project to be automatically built and imported into the other one. Is that possible?
It is possible. Right click on your project -> Build Path -> Configure Build Path. Switch to the Projects tab and add one. It will work as a library.
P.S. You might also want to check this: Creating a java library with Eclipse
Answer to this question explains how to import your own library in eclipse.
Quoting from the answer.
Just have "Project" reference your "Library", on windows the process
is (using menu / tab names)
Go to: Project -> Properties -> Java Build Path -> Projects
Client Add...
Select your "Library" project from the list
Click Ok
Click the other Ok Now your done and you can use import for classes in your "Library"

having issue with eclipse library

I am new to Droid development using Eclipse. I am trying to use PinnedSectionListView found here: https://github.com/beworker/pinned-section-listview
What I need to understand is how do I import that into my project? Do I need to load the project and create a .jar? I thought to use libraries like the one here it needed to be a .jar lib. I am a bit confused on how to use github libs like that. Also, not a big deal, I am fluent in c/c++/c#/objective c, but I am new to java. Code I can handle, eclipse ide, jar files, etc. not so much.
Any steps would be helpful, or a pointer to an example. Thanks for any help.
You have to download the library folder! Then import it in your Eclipse from the File menu! After you have done this, you have to right click your project and reference the imported library as a library project in your original project!
http://www.androidbegin.com/tutorial/implementing-actionbarsherlock-in-android/
This is a link for another library but the steps are the same.
Download and unpack the zip file
In Eclipse's Package Explorer, right click and select "Import..."
In the Import dialog, select "Existing Android Code into Workspace"
Select the dir of the unpacked file, and click "Finish", the library is now part of your workspace, which leaves the last thing to do:
Right click on your primary project and select "Properties", in the Properties dialog, select "Android" in the left panel, then click on "Add" button on the right side of the panel, select the library, click "Ok". Now you are ready to use its classes and resources.

How to know the jar files being used in eclipse

I have a java project which uses apache poi jars.
In eclipse referenced libraries two versions of poi jar is available. poi3.5 and poi3.7.
In java code im using
import org.apache.poi.hssf.usermodel.HSSFRow;
In eclipse how to know which version of the jar file it will refer.
IF there are two versions of same jar file available in class path, which one will it take?
Edit:-
In eclipse i had seen someone using a keyboard shortcut over that import statements to show the correct jar. Any one knows what that shortcut is?
I think you are looking for shortcut ctrl+shift+t
Select import statement & use above shortcut.
It takes the first library that you added to build pass.Other same packages from another libraries will be ignoring
Jars are examined in the order they appear in the classpath. In Eclipse you have the "Java Build Path" dialog that contains the "Order and Export" tab: there you can read/modify the order of the libraries.
To access directly a class in the right Jar just press CTRL and click on the class name.
Of course, having two different versions of the same Jar is a configuration bug: you should remove one of them. Also consider that the order you have in Eclipse could be different from the order in another execution environment (for example an application server).

In java, how do you import one project into another without having them in the same (Eclipse) workspace?

I've been a c++ programmer for 10 years, i'm used to just creating libraries and then linking to them from my existing project. However in java, i have 2 projects, one is my game engine, the other is the test environment that i would like to use, here is how it is structured:
com.logic.engine
com.logic.testapp
yet in my test app, i cannot do
import com.logic.engine.*;
it simply cannot find the reference.
How can I do this without having to copy and paste my engine into every program i write with it?
Package your engine as a jar, and add the jar to the classpath of the projects that use it.
In eclipse you can also declare that your test prgram depends on your game engine. The classes will then be available. Check in the build paths dialog available from the context menu in the project view.
In eclipse, right click on your test project in the Project Explorer and select Properties. In the "Java Build Path" section, go to the Projects tab and add your engine project.
You need to change the classpath to include the folder containing your engine.
java -cp /path/to/engine testapp
I just fired up Eclipse to check this out.
You should see a red wavy underline on import com.logic.engine.*; - mouse over this and it'll tell you that the import could not be resolved and offer you a number of so-called quick fixes. One of those should be Fix Project Setup - that will offer to fix things for you, in this case to add one project to the other's build path.

Categories