I have a package structure: com.report.domain.model
I would like to change it to com.reporting.domain.model. When I select Refactor → Rename on package com.report.domain.model, I only see an option to rename 'model'. I have tried switching between Project view and Package, but to no avail. I know how to make this change in Eclipse via Navigator view, but how can I do the same in IntelliJ IDEA?
In the Project Window, click on the Gears icon in the title bar and deselect "Compact Empty Middle Packages". Then you can separately select the report package and rename it.
See also: http://www.jetbrains.com/idea/webhelp/project-tool-window.html#d242351e401
N.B. As of IntelliJ IDEA 2016.3, there is a bug in the menu and when the option is selected, it has a different label "Hide Empty Middle Packages", see https://youtrack.jetbrains.com/issue/IDEA-168362.
To change the full package name:
User jkovacs has already answered this, but I'm going to cover this in a bit more detail. For example, if you want to change com.example.app to my.awesome.game, then:
In your Project pane, click on the little gear icon ()
Uncheck / de-select the Compact Empty Middle Packages option:
Your package directory will now be broken up in individual directories.
Individually select each directory you want to rename, and:
Right-click it
Select Refactor
Click on Rename
In the Pop-up dialog, click on Rename Package instead of Rename Directory
Enter the new name and hit Refactor
Allow a minute to let Android Studio update all changes
Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All:
Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:
Done! Anyway, Android Studio needs to make this process a little simpler.
Related
When I create a new Java project or open an existing one, IntelliJ doesn’t highlight any of the text nor does it suggest anything. All the code is 1 single color. I’ve marked my src file, made sure power safe is off, made sure highlight is enabled, and even reinstalled IntelliJ CE. I’ve also disabled all plugins. Any suggestions is appreciated.
picture here
Your screenshot shows that the file is not recognized as a java source file.
Go to Preferences -> Editor -> File types
Scroll down in the list of Recognized File Types and click Java.
In the list of registered patterns make sure it shows *.java.
Also ensure the file is not marked in the Ignore files and folders section at the bottom of this preferences panel. Perhaps you added it by accident (with some shortcut).
Also, while reinstalling IntelliJ, you have probably imported your previous settings. With it, you inherited this issue.
If this doesn't help, please share a screenshot of your project/module structure and setup.
Last but not least, try to create the file using the context menu. E.g. try to right click on your src folder and select new and select Java class or Package from the options. Would be good to check anyway, to see if these are valid options. If they do not appear here, it indicates the project setup is erroneous.
Solved! Thanks to #yole I did the following 'make sure that the *.java extension is listed in "Registered patterns" for the Java file type in Settings | Editor | File Types".
I am using the Lynda.com tutorial Gradle for Java Developers to learn Gradle. In the tutorial, he opens a new project with no template and copies a folder from the exercise files into the new project (I'm not sure if this is relevant to my problem). Without altering the Java class found in said folder, he right-clicks it from the sidebar and clicks "run" from the drop-down menu.
When I right-click it the class, "run" does not appear. Additionally, there is a message at the top of the text editor that says something along the lines of needing to configure an SDK. When I click on it, a pop-up saying something about "1.8" appears, as well as an "OK" button. When I choose run from the top menu, it simply brings up an "edit configuration" pop-up.
Can anyone explain to me why my layout is so different from the tutor's?
Edit: Now I see where my issue came from. The tutor was misleading with his "how to use the exercise files" video. He showed it to be as simple as clicking "open" on Intellij and opening the folder or dragging the folder to the intellij icon, without configuring an SDK. But in the tutorial video I was watching, he did something completely different by creating a new project and pasting a folder within the folder for the video, which actually ended up looking different from the template he used (His project was called GradleLab and he copied the exercise files within it, while all the other exercise files include the GradleLab folder
I am new to Java programming language and the IntelliJ IDEA 2017.1 IDE.
I just installed the IDE and I activated all the various inspections but the IDE is unable to detect the errors any time I make a mistake such as omitting a bracket or a semicolon.
This image displays the activated inspections:
This is a screenshot of my code with multiple errors but no detected by the IDE:
Kindly help me solve this problem.
Java file is not analyzed since it's located outside of the source root. You need to either relocate the file or reconfigure your content roots so that it resides under the folder configured as the Sources root.
Sources root is marked in blue in the project view. Here is the example of the properly configured project (notice the class icon is different than on your screenshot):
One more reason could be IntelliJ is running on power saver mode, this could be disabled following way:
File Menu -> Power Saver Mode
This is finally what worked for me! Phew!
My Problem: Whenever I exit Intellij and try to open up an old/existing project, I have trouble getting the builds and execute to work on my localhost. I'm just using localhost.
Here are the steps that finally worked on my localhost environment:
1. Go to Project Structure and Select Project
a. Set the SDK to 10 (“Java Version 10.0.2”) or whatever you are using.
b. (I think this was the main step I was missing) Set the project compiler output to point to where I want the compiled output to sit: C:\Users\kbala\OneDrive - MatrixCare\SoftWLearnings\Javamyfun\NewHelloWorld\out
c. Project Language Level: I chose “SDK Default”
2. Go to Project Structure and Select Modules
a. Click on src (this is where my source code sits).
b. Then, Click on the “Sources” folder icon on the top. This adds src to the “Source folders” on the right. You will see the color change to Blue
c. Click ok.
3. Then, click on “Add Configuration” (top right corner of Intellij)
a. Select + at the top left hand corner.
b. Select “Application”
c. Change the name to “Main”
d. Now click on the Ellipsis (three dots) in “Main Class”. You should now see your Main Class. Select it.
e. You should now see the execute arrow at that top right of Intellij. And you should see the build icon (Hammer).
This should work!
If you use a build system (Maven, Gradle, etc.):
Open its panel in IntelliJ, then click the reimport button. For Gradle, this button looks like a sync icon and its hovertext says "Reload All Gradle Projects".
Why it works:
Since the build system is in charge of compiling your code, it knows which files are source code. It would be a waste of computing power to look for missing semicolons in a compiled binary file, so IntelliJ won't try to find errors until it knows the file is source code.
Most build systems, Maven and Gradle included, are also dependency managers. When you write code that uses libraries or depends on a different module, IntelliJ needs to be able to understand the dependency to tell you whether your code makes sense, or whether you made a mistake like forgetting an import statement or passing the wrong type of argument into a library function. When IntelliJ doesn't understand your dependencies, it displays all your uses of imported code in red text.
I was getting the same issue, I just clicked on the re-import button on the maven panel and it solved the problem .
I had the same issue and here it is how I solved it:
Some files where ignored and I Unignored them. To do this go to Maven tab on the right panel -> right click on each project that is in grey color and click Unignore projects.
I'll add an another reason for it. For me it was Reader mode enabled. I was not even been aware of its existence. Can be disabled in Settings -> Editor -> Reader mode.
In my case was a maven option!
When you open the proyect in intellij, it create a notification.
Is there a way in Eclipse, to see empty parent packages? I have an issue freely viewing/accessing package new.galaxywar.client.resources.images.game that only contains 2 sub-packages:
I tried creating that package again, because I thought that i might not have it in my eclipse project, but it won't let me:
How do I prevent "views from filtering empty parent packages"?
In "Project Explorer" panel, click on the "View Menu" button (represented as a triangle).
Then go to "Customize View..." and deselect "Empty parent packages".
This should do the trick.
While I'm not sure how to perfectly solve the problem, I do know that you can still access the package if you try creating a new file in there, for example package-info.java.
Try doing that by starting to add a Class as usual, but specify the package to be the package you can't seem to access in the Package Explorer.
In recent versions of Eclipse, the steps in the accepted answer have slightly changed:
In Project Explorer panel,click on View Menu button
Then click on Filter
Deselect Empty Parent Packages
Eclipse IDE for Java Developers |
Version: Photon Release (4.8.0)
Build id: 20180619-1200
In Eclipse Version: 2019-03 (4.11.0)
On the Project Explorer tab press the triangle in the upper right corner.
In the menu choose Filters and Customization...
In the Filters and Customization menu unmark Empty packages and Empty parent packages.
Press OK
Now you should see the empty packages.
It's been 6 years since someone answered this question, and in the present day there is way more easiest methods to show hidden parent packages: "View menu" -> "Package presentation" -> "Hierarchical".
View menu of project explorer
Package presentation option
Hierarchical option
Wouldn't it be nice to just do a keystroke and have eclipse organize all imports in all java classes instead of just the one you are looking at? Is this possible? Is there a keystroke for it?
Select the project in the package explorer and press Ctrl + Shift + O (same keystroke as the single class version). Should work for packages, etc.
You can edit the clean up options on save to make it organize imports. That way all of your imports will always be organized.
In eclipse 3.4 just go into Window - Preferences. In the tree view look under Java -- Editor -- Save Actions.
This is how I keep my imports organized all of the time.
For Eclipse Helios, open the "Project Explorer" view, clic right on your src folder, go under the source menu, and clic "organize imports" that should work for all your project.
or just hit the combination Ctrl + Shift + O on the src folder.
If you want to run save actions against a whole project you can right click on the project, then choose Source and then Clean Up...
I have Leadbolt ads in my Android app. On every Leadbolt version, Leadbolt force me to re-update the name of the java import. For example, in my app it was :
import com.kwswsuyruzouggmtbzxb.*
Then on the update they gave me a new package with the name:
import com.izwevyqazy.*
And therefore, I have to make a change from the older name to the newer name on around 20 or more of java source code files. So, what I did is to re-organize the imports using this way in Eclipse I.D.E.:
Select in your application, the package name, the one directly under the folder "src" in your project folder.
Right click the package name and select "Organize Imports"
Please don't forget to change the names too in the AndroidManifest.xml; otherwise, your app will crash.
For mac you can use Cmd + Shift + O. Alternatively, you can do it through the menu: Source -> Optimize Imports
You can run this on individual files, or for each source folder. The option is greyed out if you try it at the project level of the project explorer. So you may have to do it a couple time if you have a bunch of modules and source folders. :)