Package explorer of Intellij IDEA like in Eclipse - java

Previously I used Eclipse, but now I am using Intellij IDEA. But I can't understand one thing. In Eclipse I have SETs in which I have a group of projects. At all I have a lot of different small projects to which I have simultaneous access and I see them all in the Package Explorer. In Intellij IDEA I see only one project, and this is not convenient for me.
Does Intellij IDEA have an analogue Package Explorer? How can I see many projects in one window?

I believe you cannot open multiple unrelated projects in one window like you do in Eclipse.
You'd need to open them in multiple windows, File > Open ... and you'll choose a new window. I also wished Intellij could open multiple projects in single window. But now I get used to it. Just click CMD + ` to switch between Intellij instances on OSX.
If they're modules of your project, then you can add them from File > New > Module From Existing sources...

Related

How I run individual java file in IDEA?

I am a java beginner, the first java IDE I downloaded was Visual Studio Code, it was very easy to use and everything is auto configured. But it kind overheats my laptop all the time, so I want to try IDEA, so far it's a very good experience, except when I open a java file and tried to run it in IDEA, it always pops out this run configuration window and I don't understand how to configure it. In visual Studio Code I can open any java file any time and run without any issues, but now I have to go through creating projects every time. Is there any solution for this?
From how the file icon looks:
your file is not recognized as the part of the sources of your project. Check the project settings to ensure that source directories are correctly set.
I'd also recommend you to look up and follow the conventions for the directory structure of java projects.
Once you've fixed the problem with sources, you'll see "run" icon next to your class, main method, or when you're right clicking the file.
Command-line
To run a single file, there is no need for an IDE.
In Java 11 and later, the java tool at the command-line can both compile and execute a single-file Java class. See JEP 330: Launch Single-File Source-Code Programs.
If your class named HelloWorld were in a file named HelloWorld.java, on a console type:
java HelloWorld.java
To be clear: The java command-line tool really only executes Java apps, while the javac command-line tool compiles Java source code. As a convenience, the java tool was enhanced to effectively call javac on your behalf for a single-file.
JShell
If you just want to run a few lines of Java, try JShell, the REPL tool bundled with Java 9 and later.
See:
Java Shell User’s Guide by Oracle
JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)
Search to learn more and find tutorials.
BlueJ
Using an IDE such as IntelliJ, NetBeans, or Eclipse can be a daunting task for the new student of Java. Those IDEs are heavy-duty tools designed for professional programmers.
I recommend using an IDE designed for beginners. BlueJ comes to mind, designed specifically for educational purposes. BlueJ makes getting started with Java easier.
If you insist on using IntelliJ, read on.
If using IntelliJ, define a project
IntelliJ is not designed to work with single files. IntelliJ expects you to work within a project.
I strongly recommend learning the basics of Maven to create and drive your new project. By defining your project in Maven, the configuration is independent of any one IDE. You can move your project between major IDEs such as IntelliJ, NetBeans, and Eclipse.
Maven is also very useful for downloading needed libraries ("dependencies") that you may want to leverage in your work. And Maven is good at packaging your Java app as a JAR (or WAR or EAR).
In IntelliJ, choose "New Project". In the New Project window, click the Maven item on left. Check the Create from archetype box. Scroll the list to find item for org.apache.maven.archetypes:maven-archetype-quickstart. Under that, choose the "RELEASE" item. Click Next button.
In Name field, enter something like MyFirstProject. Click Next button.
On the Maven settings page, just click Finish.
Wait a moment for IntelliJ to download some stuff and configure your project. Eventually you should see a BUILD SUCCESS message in the Run pane.
You will also see a pom.xml file displayed. The POM contains your settings for Maven to run your project, in XML format.
Change the <maven.compiler.source> and <maven.compiler.target> elements to the version of Java you are using. The current version is Java 17.
After editing the pom.xml, look for a little floating windoid with a tiny Maven icon. Click the icon to have Maven process your changed POM. Wait a moment.
In the Project pane, navigate to the App file. There you see code to print “Hello World!”. Let's run that code now. Click the green triangle button on the left, in the gutter, next to the main method line. A pop-up menu appears offering a Run item. Choose that item to run the app immediately.
Down in the Run pane, you should see the results, the Hello World! text.
At this point you can add your single file to the org.example package seen in the Project pane.
By the way, you can change that package name by context-clicking and choosing Refactor > Rename….
Later, learn to use the Run/debug configurations feature of IntelliJ.
Know that you need not create a new project for each time you want to do a little experiment. Create one project for such experiments. Keep adding new .java class files for each experiment. Delete old class files you no longer need.
Eventually, I suggest updating the versions of various items in your POM. The QuickStart archetype is not configured for the latest versions (for reasons I cannot fathom).
And when you learn about unit testing, replace JUnit 4 in the POM with JUnit Jupiter (Aggregator) to use JUnit 5. One of the benefits of using Maven is that you can easily switch out dependencies such as going from JUnit 4 to JUnit 5.
The IDE needs to know what's called the entry point of the program, i.e. where to start running your code. That's what the "Edit Configuration" window is wanting you to do.
If your file "Lab3.java" is in a package, make sure to fully specify that in the field you have in red. Otherwise without knowing how your project is structured (as the other answer alludes to), it's difficult to pinpoint what we're missing here.
When you create your IntelliJ project, add a directory /src right at the root of your project. Right click on that folder and tell IntelliJ that you wish to mark it as a source root. The directory should turn blue in color.
Put your packages under /src. IntelliJ will know that those are Java files.
When you want to run a class with a main method, choose Run->Edit Configurations. Tell IntelliJ that you want to add an Application. It should prompt you with the classes that have main methods in them. You'll have no trouble running them.
Use Maven or Graddle. Make sure the project is configured with the build tool enabled and integrated, it will do basic things automatically. If you are not sure, please create a new project and add your files in. Steps:
Open the IDE
New Project
Choose from the left side bar "Maven" or "Graddle"
Give it a name and the location in your machine.
Click Finish
Now you have the project ready. You need the appropriate method to run in java. A main class. In IntelliJ you can just type "main" and the auto-complete will add it for you, make sure you inside the curly brackets of the class {}. More info about the main class. You seem to have this nailed down.
Lastly make sure you have a JDK installed in the IDE. I am pretty sure this is your issue here, make sure to use one of the option IntelliJ provides. A full guide from the developers is here and should satisfy your needs. I would suggest OpenJDK for a beginner, because that served me well at the beginning, at the end of the day its your choice.

How to up and run java code in JasersoftStudio?

I would like to know something if possible. As I used JaspersoftStudio, I noticed that when creating new project folder it always came up with JRE library. I also see java editor in there as well. Is it possible to write and run java code in JaspersoftStudio GUI?
Please share your ideas on here.
Regard,
Sakura
As you may have noticed, Jaspersoft Studio is a repackaged eclipse. And yes it is possible to run Java code in it, it's just a bit more cumbersome than in vanilla eclipse.
In any of your jasper projects (the project icon in the explorer should have a little J), right click and open Properties.
In Java Build Path, add a new source folder.
In your new folder, create a new File, and put your main class in it.
You can now run it with the keyboard shortcut Alt-Shift-x j. I don't know if there's a menu for that too.
Additionally if you have an existing eclipse project, you can import it directly into Jaspersoft Studio using Import... Existing Projects into Workspace.

Eclipse. Different Workspaces. Can't save same project name

all. I've read the existing threads on this topic.
My understanding is that if I use different workspaces in Eclipse, I should be able to save the same project name. But I'm not able to and not sure why.
In Windows 7, I have Eclipse Kepler (Java) installed with the C++ and Python plugins. I created three workspaces:
C:\eclipse\workspace-c++
C:\eclipse\workspace-java
C:\eclipse\workspace-python
... and I want to create HelloWorld projects in each. I can create the first project, but when I switch perspective and try to save the second in a different workspace, it says that the "project already exists."
Any ideas? Thanks for your help.
It is definitely possible to have Eclipse projects with the same name in different workspaces
Based on your description, it sounds like you may not actually be using multiple workspaces.
The following describes two ways to how start Eclipse in a specific workspace.
To start up eclipse using a specific workspace you can do the following:.
eclipse.exe -data c:\path\to\my\workspace_1
-data is used to specify the workspace on the eclipse command line
You can also switch workspaces via File->Switch Workspace
Could it be in a hidden working set? In the Project Explorer, expand the menu (downward arrow on top right) and in Select Working Set, make sure all working sets are selected.

How to organize jar files in a libraries folder in Eclipse?

I have a Java Project in Eclipse, and a Java Dynamic Web Project in Eclipse. In the former, all the jar files are shown individually under the top-level project folder. In the latter, the jar files are under a Libraries folder and the navigation is more convenient.
Is it possible to organize them in the same way in the Java Project also? If so, how?
Update: It is the Project Explorer View. For the Java Project, I see: "my_project_name" with the arrow expanded to point downwards, then I see: "package_icon src/main/java" and below that "package_icon src/main/resources" and then 20 jar files one below the other: "jar_icon activation-1.1.jar", ...
For the Java Dynamic Web Project I see: "my_project_name" as above, then I see: "JAX-WS Web Services" (unexpanded), then "Deployment Descriptor" (unexpanded), then "Java Resources" which I have expandeded, so I see the components of it below, of which the first is: "package_icon src/main/java", then below it, "package_icon src/main/resources", then below it "libraries_icon Libraries" instead of 20 jars! I have the option of expanding Libraries if I really need to see the 20 jars.
The only option I found to make things prettier in Eclipse Kepler is to:
In the Project Explorer window there is a down arrow in the upper right corner. Select that and then Customize View.
Select 'Libraries from external' and then OK.
Kind of cheesy...
EDIT: Of course I had to go and do some more digging...and it looks like I'll have to try this and see how it works.
Similar to M Miller's answer (but for Juno), click Show 'Referenced Libraries' Node in the dropdown of the Package Explorer window:
I'm using:
Eclipse IDE for Java Developers
Version: Juno Release
Build id: 20120614-1722
I noticed this "feature" on Eclipse Juno (latest version), when you have a jar file added to the build path it is not shown as a single file on the project.
Try removing one of the jars from the build path to see if it shows up again.
I couldn't find how to turn it off though.
BTW... the project layout for your "Java Project" is more akin to a "Maven Project", which is a bit more powerful.
You should change into the Package Explorer by Window > show View. It will display all the referenced libraries in a Referenced Libraries folder.

Possible to have several instances of Eclipse open simultaneously?

I'd like to know if it's possible to have several instances of Eclipse open at the same time. I'm using it for Java development. I know I can have several files from different projects open at the same time (at least that's what it seems to me), but whenever I try to open a second instance it shows me the following message:
alt text http://img46.imageshack.us/img46/5033/sxbz3mti34afybrafhc32m0.png
Is there any easy way to have several instances of Eclipse open, each one with a different project?
Thanks
Either create multiple workspaces (Preferences / Startup, tickbox to ask which on every startup)
Or more likely, I think Window / New Window will open a second eclipse viewing window on the same workspace.
yes, each on a different wokspace.
Projects and Workspaces in Eclipse are different. A workspace has a set of global settings and then it has a set of projects.
There are two kinds of project. Projects in the workspace and projects outside the workspace. If you use in the workspace projects (for example, by telling eclipse to make a project via a source control checkout), then it can only be in that workspace.
If you create projects outside the workspace, then you can import each one into as many workspaces as you like.
You can make as many workspaces as you like. Each workspace can be open in only one instance of eclipse.
A better answer to have only the resources from certain project in the new Window is by right clicking the project and select "Open in New Window"
You may want to use Working sets.
A common problem in Eclipse is that
your data in your workspace grows and
therefore your workspace is not well
structured anymore. You can use
working sets to organize your
displayed projects / data. To setup
your working set select in the Package
Explorer -> Show -> Working Sets.
I tend to use different workspaces for different contexts, not just working sets. For that none of the answers above is satisfactory, instead you might want to use the "-data" option on the command line. That allows you to specify the workspace to open, if that is different from the already open one, then a new Eclipse instance will be started.
See http://labs.distriqt.com/post/844 for more details.
There is a way. I have several installations of eclipse in separate folders. Each setup for a different language/job and perspective (CF, Java, Birt). Each has its own workspace so they don't interfere with each other. You can work out if your machine can handle the multiple instances.
If I understand well, your problem is that you would like not to see the other projects while working on one. What you could do is close the projects you're not working on, and then in the package explorer, choose filters > closed projects. This way the closed projects no longer appear in the package explorer.
If you want multiple Eclipse instances open on the same workspace (with the same projects) then you want to use 'Window > New Window'. This will even let you drag views from one window to another.
If you want to display different sets of projects in each Eclipse Window then I'd suggest you use set up a 'Working Set' for each combination of projects you want to work with. You can then select a specific working set from within the Package Explorer. You can create working sets using 'File > New > Java Working Set'.
Something else to consider is that a Workspace is more than just a group of projects - preferences are all stored at the Workspace level. This means that it is quite easy for your preferences to get out of sync if you work with multiple Workspaces.

Categories

Resources