Is there any way to skip some Java files when compiling under Eclipse?
Remove the class from the build path. You can do this for a single file or group of files by selecting them in the Project Explorer, then right click → Build Path → Exclude.
You can always exclude the item from being built. Right click on the file and go to build-path. Then click exclude.
Delete (or move) them. It can't compile what isn't there ;)
Note: Other forms of removing the content you don't want compiled also work.
This page should help you. If you wish to remove a file from compilation you can delete it, as cdeszaq suggested, or you can change the extension of it(For example if you have test.txt changing it to test.txtz would pretty much make it un-openable)
There's another way to do it. I discovered it by first using the Build Path -> Exclude option in other answers, as Eclipse said something about configuring filters.
Right click the project -> click Properties -> click Java Build Path -> click Source tab -> select ProjectName/src -> click Edit... (or double click Excluded) -> add an Exclusion pattern like com/blah/blah/blah/, potentially with wildcards.
It looks like the wildcards are your standard * and ?, but they also have **, which appears to be for wildcarding any number of folders, which must imply that * and ? are for only wildcarding a single file/folder name.
Related
Related: IntelliJ does not show 'Class' when we right click and select 'New'
In the above accepted answer, it says the "New" does not give the option for Java Class because it was not the source root (blue directory).
However, as you can see, even though where I am right-clicking is source root, indicated by blue box, it is not giving me the option for Java Class
Any idea why?
This directory is imported from git so it did not follow the usual "Create Project" for java directly from Intellij
You are right clicking in the wrong spot -- youre "too high" up the tree. Go to where you code is (as in the package under "src") and try it there and you will see the option for a New Class.
EDIT: You don't need to be in the source root. You need to be in the source directories themselves. The blue dot I believe is a git status indicator. What you want is an entirely blue folder.
Go down under "src". Likely under "src" then "main" then "java", and you're there (that's blue for me) and then you will see your package folders. Below those are where you likely want to be adding classes.
As many mentioned above you can right click on the folder you would like it in. In your case:
If you push Alt+1, it might be easier for you to right click
src > New Java Class
Alternatively you can push:
Alt+1 (Project View)
Alt+Ins
or
Ctrl+Alt+Ins
1) Right click on src
2) Click New > package
3) Name your package and press OK
4) Right click the newly made package
5) New > Java Class
If the folder where we are trying to create the class is not marked as source or test then the option is not available.
Right click the project and go to project structure then under project settings -> Modules, Select the folder where you wanted to create class and mark as Source or Test appropriately and then click apply and ok.
Now you will see the change of color of the folder/package(Sources->Blue, Test->Green) and you will get the option to create the class.
This worked for me.
I know this is an old thread, but it happened to me because my gradle files were not synchronized. So if you are within a team working on same project and face this issue, make sure to run gradle sync.
You should go inside java project then you can create java class.
So, we are integrating another project in our code base. It does not follow our formatting rules. I have auto-formatting upon save configured. So, I could go to each file and save it again but is there a way to script Eclipse so that it applies formatting rules to every single file in my workspace?
Right click on the project(s) (can multi-select) and choose Source -> Format in the menu.
Try Source -> Clean up..., Use custom profile -> Configure.... it has more powerful options there.
Make sure you are in Package Explorer, then right-click and select the Source menu. Some of the other views (e.g., Navigator) won't show this option.
I would like to have the javadoc comments contained in a jar file show in eclipse when I hover over a class.
For example, after downloading JODA-2.0, three jars are obtained:
joda-time-2.0
joda-time-2.0-javadoc
joda-time-2.0-sources
(http://sourceforge.net/projects/joda-time/files/joda-time/2.0/joda-time-2.0-dist.zip/download)
In eclipse, [right click project -> Properties -> Java Build Path -> Libraries -> ADD JARs...] includes the binary in the project (can reference those classes) for joda-time-2.0.jar.
But how can I link in the sources/javadoc comments contained in the other two jar files so that when I hover over those classes I see the javadocs?
Adding the other two jars (joda-time-2.0-javadoc.jar and joda-time-2.0-sources.jar) to the build path does not link the javadocs or the source.
Right click over the project -> Build path -> Configure build path
In the new window, go to the "Libraries" tab.
Select the library and expand it.
There are 4 child options. Select "Javadoc location" and click the "Edit" button on the right.
Now you can add a jar file containing the docs. This would be just a zip file with the extension changed to jar. Make sure inside the jar the index.html is in the root. You can press the "Validate" button to check everything is ok.
You can try to CTRL + click on a class that has no source attached (do that in editor). When it shows you some info about the class you'll see the button that guides to attach source dialog. Click it and in dialog that pops up pick the source/javadoc location for your class.
You can also do that from project build path settings you are mentioning: pick libraries tab, expand the library (jar) you want and you'll be offered to pick: source attachment, javadoc attachment, native library location, etc. You just pick whatever you want and edit its current settings.
Or you can do as #JB Nizet said...
Right-click on the jar (the one with the class files), choose "Properties", the "Javadoc location", and choose the jar file with the javadoc. Do similarly for the source jar, using "Java source attachment".
You can also edit the classpathentry in the file ".classpath" in your eclipse project. This can be helpful if you want to modify many entries at once or if you want to generate the path.
e.g.:
<classpathentry kind="var" path="HOME/3rdparty/junit.jar" sourcepath="/SOURCE/junit_src.zip"/>
The easiest way is :
Press control+(The word for which you want to see the Java doc)
A page will appear that has a button for attach source.Click This
Select External location.
Browse The location to Java folder than your jdk .Than select
src .zip.
press OK.
The Problem is Solved.
I am using Eclipse & have some packages that I want to export into a JAR file (not a runnable ones). I just need it so I can import it into another Java project to use the classes.
When I exported them, most of the packages are exported but there are a few packages that appears to be empty. I've selected Export generated class files and resources and Export Java source files and resources. I also tried changing the option here and there just to figure it out but it still gives me the same results.
Is there a configuration that I missed?
You would probably be better off reusing Clean way to combine multiple jars? Preferably using Ant (that's what Eclipse is trying to do, under the scenes).
When you right click on a project, then pick Export ... you can in the following menu choose Export as Java>JAR File.
Then a menu should pop up, which lets you exactly choose from a list which folders/files you want to export into the JAR. (On the left, as Select the resources to export.)
For exporting...
1. Goto File -> Export.
2. Under 'General' category select 'Archive File'.
3. Give name and path for where to save the archive.
For importing...
1. Goto File -> Import.
2. Under 'General' category select 'Archive File'.
3. Browse the exported archive.
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.