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

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.

Related

Intellij Tree with custom files in plugin

I'm developing intellij plugin and I have tree structure with files and directories (not related to current project nor file systems). Is is just some virtual tree structure provided by rest service. I want to display it in ToolWindow with all common staff like colors, file type icons etc.
Is my usecase already supported by intellij?
Which classs support this?
The closes one related to my case I found trees from vcs package but it is commit / change related.
I don't think what you want to do is formally supported by JetBrains, but you could create a "fake" project in Intellij IDEA as long as the files and directories you want to appear in the tools (Project) window have a single parent directory.
I had a folder named "docs2" which contained some random notes and documentation files of various types such as txt, pdf, zip, html, js and bak. I opened that directory as a project in Intellij IDEA's Project window as follows:
Create an new project: File -> New -> Project... -> Static Web -> Static Web, then click the Next button:
On the next screen populate the Project location field by navigating to the folder containing the files you want to open in Itellij IDEA, and give the project a suitable name. Then click Finish.
After that Intellij IDEA will treat the directory as though it was a static web project.
Notes:
Intellij IDEA won't necessarily be able to handle all of the project files created in this manner. For example, when I opened a pdf file it was opened in another application, and when I tried to open a zip file nothing happened. But other known file types such as *.txt, *.html and *.js can be opened and edited as though they were files in a "real" project.
When you open the directory as a project Intellij IDEA will create some files in that directory: a *.iml project file and a .idea folder containing configuration files, so you will need write access to the folder that you open as a project.
I also tried opening the directory as an Empty Project in Intellij IDEA, but that only worked partially; files under the parent directory were shown, but for some reason it would not show any sub-directories in the project.

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.

Runnable JARs missing Images/Files (Resources)

When I export my code as runnable JAR from eclipse all the files that I've set it to grab such as button images and other files are missing even though they are actually in the JAR. I've added getClass().getResource in front of the files but then when I try to run the JAR nothing even happens, any suggestions?
Seems like you not putting your stuff in the right sense. In order to make it work, follow these steps :
Right-Click your Project in Project Explorer Tree.
Go to New -> Source Folder and then provide any Name to the Source Folder.
Now manually add your stuff to this Source Folder so created by you, like if you want to add images then make a New Folder, by manually visiting this Source Folder through File System.
Name this New Folder as images and copy your images to this Folder.
Now go back to your Eclipse IDE and Refresh your Project from the Project Explorer, by Right Clicking your Project, here you be able to see your added content now after refreshing.
Now in order to access, say any image, you will use.
getClass().getResource("/images/yourImageName.extension");
which will return one URL object. Do remember the first forward slash, in this case, since whatever is inside your Source Folder is accessed with the help of this, in simpler terms. Now when you will Run your project, the content of this Source Folder will be automatically added to the bin folder and when you will create a Runnable Jar, then the stuff inside your Source Folder can be accessed as it is.
The path needs to be right for the resource.
For "foo.gif" being at the root of the jar, you must refer to it using "/foo.gif".
If the program works correctly after a complete clean and rebuild, but fails as a jar, you most likely do not have the files included in the jar.
Try to put the folders in the jar the same way that you got them in the program. Put in the same resources in the same places that you have them in the project. The jar will reference to them the same way as in your compiler did.
You need to get the images using stream like this -
this.class.getClassLoader().getResourceAsStream("test.jpg") and make sure the images are present in the jar which you are referencing.
As nIcE cOw said, you just need to create a Source Folder in you Project Explorer Tree.
All the files inside that folder will be in the root project folder.
To refer to them, you must write your projects name slash the file name as it:
getClass().getResource("ProjectName/image.extension");
I hope this helps!

How to import a Java program into Eclipse?

I have some java source code. It an just an archive which is four folders.
Folders MAIN, DATA, TAGS, USER_INTERFACE. Each folder contains a few class files.
I see how everything works together, but can't see to get the program to import correctly or run. I did find a MANIFEST.MF.
What is the proper way to import such a project?
Create an Eclipse project. Under the project settings, select the "Java Build Path", and add each source folder (and remove the default src folder that Eclipse may add for you).
If necessary, you may set the output/build folders for each source directory, and clear Eclipse's default bin output directory. Check the "Allow output folders for source folders" to enable this, then set each source folder's output folder.
(You may or may not want to keep compiled classes in individual directories.)
If there are class files in the project that aren't generated from source in the project, in the same dialog, select the "Libraries" tab, and click the "Add Class Folder" button to add dependencies from within the project.
It doesn't seem that your source code is an eclipse-importable project (it would have to have a .classpath and .project file in the top level directory for that).
You should instead create a new Java project. For simplicity, set the project's location to be the parent directory of your MAIN, DATA, etc. directories. Then after the project is created, configure a source folder for each of MAIN, DATA, etc. (right-click the project, choose Properties > Java Build Path, then work in the Source tab). Your source folders should then show up in the navigator and the project should be able to be compiled.
Create a hello world project in eclipse and understand the project structure in eclipse.
And then manually import the files it is simple and avoids a lot of confusion especially for somebody new to the environment.

Ignore folders beginning with dot in IntelliJ

In project I work on there are folders with name started with dot sign. They are used by external tool to generate actual code/properties variation based on some properties. IntelliJ complains about java classes in these folders (path doesn't correspond to package name). What I'd like to do is to force the compiler to ignore specific folders (they shouldn't be used in build anyway). I found Settings->Compiler->Excludes option but I can't see the dot started folders when I try to specify exclusions. Pasting folder path doesn't work either. Not sure if it is like that because of Intellij or mac hidden folder issue. Any hints?
In the module editor, set the folder to be excluded from the project, i.e totally ignored. Select the folder and then click on the "Excluded" button. Then the folder will be shown in red and will not even show up in IDEA project view, and no indexing or compiling will take place on this folder.
You can "Show Hidden Files and Directories" which should be the last icon in the Select Path window.

Categories