My IntelliJ had maven prob about package(folder) - java

screenshot of my problem
IJ recognizes main.java as a package, not a normal folder.
This is maven project.
How can i solve this problem?

You have incorrectly marked src as a source root (notice that is is blue) - right click and "unmark" it as a source root.
Then, locate the src\main\java folder and right click on the java folder -> mark as source root.
Once you have done this, intellij should recognise your folder structure correctly.
You might also want to mark resources as a resource root.

Related

Intellij not recognizing source directory in project

Java EE. Maven.
Package resources marked as Resource root, package java as Source root also.
In my class I have path String property\file.properties, but when I run it, IDEA throws an exception :
"java.io.FileNotFoundException: property\file.properties (The system
cannot find the path specified)"
But when I change path String to src\main\resources\property\file.properties it works.
Packages marked as source. In Project File - Module I also see that this directories marked as source roots.
How can I fix it, any ideas?
I have already tried invalidate cache.
P.S: When I rename my string path with shift + f6 file also change name.
EDIT:
Source root packages
In IntelliJ IDEA Ultimate as whereas the Community Edition, you can mark any folder in your project as your Sources, Tests, Resources, etc directory.
Right-click on your project root directory ➡ Select Open Module Settings in the context menu.
In the Project Structure window that opens, choose a folder in your project ➡ then select to 'Mark' that folder as your Sources or Resources directory depending on your needs.
You should see a list of marked folders in the right pane of the same window. Click the Apply and OK button when done to save your new changes.

In IntelliJ, how to exclude \target\*.html files in search (everywhere) result?

I have a IntelliJ java project, there are some HTML file templates under my source folder. This project is built and output to \target\ folder. The HTML file templates are copied over to the target folder as well.
I have been trying to exclude the HTML files in target folder from "search everywhere" result.
I have already set the \target folder as 'Excluded' in 'Project Structure settings'.
But this is not working: although target*.java and target*.js are excluded in this way, the target*.html files are not. I think IntelliJ's 'Excluded' folder only exclude these files it considered as source files, but html is not.
Is there any workaround for this? I am using IntelliJ Idea 2016.1.3
Normally, I'd do the following:
in your module settings on the Sources-Tab, in the right pane you click on the directory and then on "Excluded". The directory will then appear in the left pane as an "Excluded Folder"
I was satisfied by that, but it wasn't exactly what you wanted to achieve.
Would it be better to configure a custom scope? Try this.
In my case, I had the target folder marked as excluded but also, partially, marked as source. This caused the problem for me.

src folder causing errors in package declarations in Eclipse

In my project, my src folder is under X/Y/A.B.C/src.
Under src, I have folders A/B/C/*.java files and A/B/C/D/.*java files, etc.
I'm getting my package names all starting with src, for example src.A.B.C.
My packages should start with A. And this causes an error in every class because my package declaration doesn't start with src.
I've tried fooling around in the .classpath and with the java build path, but can't get the package names changed.
You are using one folder up as your source folder.
Right click on the folder, Go to build path, Click Remove from build path.
Now, go one folder down, right click on that, go to build path, and click Use as source folder.
For example :
Wrong src folder selected.
Right click on Custom and Remove from Build Path
You will have something like this.
Right click on src and add Use as source
BANG!!! This is what you wanted.

Directories rendered as packages in Intellij Idea 13?

After a rebuild of my android project i saw that the src folder and other folders(assets, libs etc) have turned into packages.(Packages in Intellij have a folder icon with a ball inside it)
Due to this, I also got errors in all files inside src folder. (for example see SearchActivity.java , 1st line).
I am new to Intellij so apologies if this sounds rudimentary.
As of 2019.2.2, it's easiest to do File > Project Structure..., double click Modules, and then under the "Sources" tab right click the folder and un-mark it as a source folder.
It looks like the Shopper folder has been set to being a source root, instead of the src folder. To fix, turn off Flatten Packages and Compact Empty Middle Packages, right-click on src, go to Mark Directory As, and then Sources Root. Then un-mark the project folder.
You can also do this from Project Settings.

Why isn't intellij giving me the option to create new classes?

Here's what I'm seeing:
Normally I can choose "New Java Class" but for some reason I'm not getting this option. I created this project by opening an empty directory and building it out from there. I've seen this question, but that answer didn't help me. Here's my module settings:
Even if I open my pom.xml directly as a project, it still has this problem. How do I fix this?
The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).
If this is not the case, right click your root source directory -> Mark As -> Source Root.
For some reason, intellij didn't recognize my directories as packages. If I created something directly from the java directory, it would give me the correct options. I fixed this by deleting everything under java/ and recreating it. This may be an intellij bug.
This happened when I was trying to add classes to a generated package using xjc plugin.
Intellij allows to add classes only to packages which are correctly names and have the "source root" status.
Can be fixed as-> right click on the directory where you're not able to add classes:
Mark sources root
refer image for clarity
This worked for me :
Right click the java folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
Right click the myproject folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
So basically had to mark some inner folder as Source project and alter mark parent project again as Source project..
Hacky way but this worked for me.

Categories