Russell Bateman March 2015 August 2015
You might skip this self-conscious rant about Eclipse and just go on to the set-up steps.
It's hard to begin saying goodbye to Eclipse. It's been a loyal friend for over a decade. At home, on Mint 17 (and earlier Mint and Ubuntu releases), I have no particular problems of stability. However, at work on Fedora 22, it simply is too horrible to continue using (for other folk there too after we all were forced by policy to upgrade from Fedora 20 to 22).
I'm not too put out. Since I first began using IntelliJ IDEA over a year ago (at another company), I found much I didn't like, but much I did, in particular, the debugger which is a lot better than Eclipse's and now in version 14, it's even better with a number of insanely desirable features.
I had switched over to PyCharm earlier this year already and have liked that a lot better than PyDev (a lot). With the switch to Fedora 22 and the continual hanging, badly working features (really, really hard to move views around) and the need to bounce several times per day, I'm giving up and moving to IntelliJ Community Edition with even thoughts of purchasing the full edition for myself.
IDEA is really the Java IDE version of something called IntelliJ from JetBrains. PyCharm is the Python equivalent of IntelliJ IDEA. Other language targets have similarly interesting product names. As for cross-integration of these, my only real interest being Java and Python because that's what I use at work, I haven't succeeded in getting them to work either because the Community Editions do not integrate or, more likely, because I just haven't gotten serious enough about it.
I have an older set of IntelliJ notes; these were made a bit under duress, express frustrations I had when I was forced to use IntelliJ and didn't want to, but contain some useful comments especially connecting Eclipse practices with IntelliJ.
The first time I used IntelliJ, it was version 12 and it seemed a bit clunky to me. What I did like pretty quickly was the debugger, however. In version 14, the debugger is even better. The comparisons below are with Eclipse, of course.
What's not so good?
See these notes.
Here's how that went...
This isn't exactly possible. What I do is open multiple projects simultaneously. Do File → Open Recent, choose a different project than the current one in the "instance" you're doing this from, and it will open a new IDEA "instance" that you can move to a different workspace.
A disadvantage is that any modal dialog open in any one "instance" will prevent use of another "instance" from working until satisfied. This is especially annoying when comparing Settings for the IDE or for modules between projects.
When you update IDEA, after downloading the new tarball, expanding and launching it, you get asked where to get the former settings from:
The first option just takes it from what IntelliJ recognizes as what you've been using, a hidden subdirectory. This restores what you've been experiencing. Alternatively, you can navigate to an older or different configuration subdirectory or installation. If you really don't want what you've been seeing, then choose the last option.
If you miss the chance to go find the instance you've been using, you'll never be asked again. To get this chance back, kill IntelliJ IDEA, go to your home directory, remove the .IntelliJIdea2018.1/ subdirectory, and relaunch the new instance of IntelliJ IDEA you've installed. If it doesn't name what looks like what you've been using, then choose the Custom location, then navigate to and chose the .IdeaICwxyz that corresponds to what you've been using. For example, if you've upgraded to the 2018 version, choose .IdeaIC2017.N, where N is the greatest number.
See Can't edit launcher on how to update the IntelliJ IDEA launcher in the panel in Cinnamon.
Before we get on with working with our first project, let's do some configuration.
Note that settings, very complex, are kept in a subdirectory off your home subdirectory, entitled something like .IdeaICyyyy.release (example, .IdeaIC2017.2. If you install IntelliJ on a new host and want it to look like it does on another, older host, copy this subdirectory before starting IDEA the first time on the new host.
At this point, things get real specific about how you want to run your life. I'll show you mine; you can figure out yours later.
The very first place I head for is the Keymap. There, I'll do a major Eclipse thing as described in my older notes here. I fix what Ctrl-D means.
I want the newline at file's end. Especially in Python, it's a good thing.
I like to Show line numbers and method separators.
I like to lose Javadoc initially; I'll open it if I want it.
Here, I like a different font; IntelliJ ships with a much better font, Source Code Pro. However, in order to get that, I have to begin differentiating my settings from the Default ones.
#!/bin/bash set -euo pipefail I1FS=$'\n\t' mkdir -p /tmp/adodefont cd /tmp/adodefont wget -q --show-progress -O source-code-pro.zip https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.zip unzip -q source-code-pro.zip -d source-code-pro mkdir -p ~/.fonts cp -v source-code-pro/*/OTF/*.otf ~/.fonts/ fc-cache -f rm -rf source-code-pro{,.zip}
Next, I hate the retro, black background most people like today. It reminds me too much of my old dumb-terminal days back when I started working. I write on white not black paper; it's the natural metaphor. However, staring at a stark, white screen all day is murder on the eyes. I'll soften it a bit by finding a wheat-colored alternative for my editor window background.
When I debug or run tests, I'll get a console, so I change the Console Font to Source Code Pro.
Here's where I'm the most anal... I'm an Allman not a KNF sort of guy. We left that ugly mess behind in the late 80s/early 90s, then the Sun Microsystems Java guys found a way to sneak it back in. That's confused all the young folk who weren't along for the ride in the 80s. They think it's okay to leave your code messy, harder to read and harder to comment out without syntax errors.
(Also, check out River (typography) which is a notion that affects the careful vertical alignment you sometimes see when my code get declarative, like defining variables, especially manifest constants and data.)
Anyway, smart guys that they are at IntelliJ, they have leave us the ability to import settings from elsewhere, ... like Eclipse! (Here are my own Allman-conformant settings, if you care.)
You can set up how your code is automatically created with company copyrights, Javadoc statements, etc. Whether and/or how may be something you'll deal with later after using IntelliJ.
Working on larger projects with other and on older code gone stale, I find it super annoying to have to dismiss the Messages Make window that pops up to remind me of all the deprecated interfaces in use when I have little or no control over them being consumed in the first place. To disable, go to File → Settings... → Build, Execution, Deployment → Compiler → Java Compiler and uncheck Report use of deprecated features.
File → Settings... → Build, Execution, Deployment → Compiler → Java Compiler
IDEA sets up a Javadoc comment automatically whenever you create a new class. Here's what you can do to populate @author, @since and other goodies.
/** * * @author Russell Bateman * @since ${MONTH_NAME_FULL} ${YEAR} */
It's possible and very convenient to set up Git if you're that way. I prefer to use Git outside the IDE at the command line.
Your chance to tell IntelliJ that you use Maven. Click on Maven; likely, if you've set Maven up correctly, you'll find that IntelliJ already knows where to find it and there won't be too much to do.
Next I move on to demonstrate writing a tiny hello-world project with Maven.
It appears that a .iml is expected in every subdirectory/folder that is a module.
If you're not using Maven, don't worry about this now.
If you let IntelliJ (or a Maven archetype) set a project up for you, it's going to have that overly deep, complicated filesystem of subdirectories described in the set-up section above.
I never really was a fan of Maven, but it's grown on me. It solves a lot of problems. 30+ years ago I started out as the team's Make guy, then moving on to Java a decade ago, I became an ant guy. Once, I almost became an Ivy guy, but that was short-circuited. Now I'm a Maven guy (and still an ant guy when necessary).
Here are my steps from leaving off those above...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.etretatlogiciels</groupId> <artifactId>intellij-trial</artifactId> <version>1.0.0-SNAPSHOT</version> <name>intellij-trial</name> <description>Experimenting with IntelliJ.</description> <properties> <junit.version>4.12</junit.version> <log4j.version>2.1</log4j.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <sourceDirectory>src/main/java</sourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> <resources> <resource> <directory>src</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.etretatlogiciels.IntellijTrial</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> </project>
What am I getting out of this POM file, you ask? You're getting a project name, a group id, artifact id and the JARs for JUnit testing and Log4j use. You're also getting the capability of building an executable JAR for distribution.
The highlighted lines above have content you need to understand, think about and whose presence you must ensure.
If successful, you'll find your executable JAR someplace like this:
~/dev/intellij-trial $ find . -name '*.jar' ./target/intellij-trial-1.0.0-SNAPSHOT.jar
There are many times when IDEA doesn't compile code and it's a mystery why. Before pulling your hair out, rewriting pom.xml, restructuring package paths and class relationships, try try File → Invalidate Caches/Restart then clicking Invalidate and Restart.
File → Invalidate Caches/Restart
Invalidate and Restart
This format is used by all the recent IDE versions by default. Here is what you should share:
Edit $IDEA_HOME/bin/idea.properties and set thus:
idea.cycle.buffer.size=disabled
(...where $IDEA_HOME on my system today is /home/russ/dev/idea-IU-203.7148.57).
Nota bene: This setting is not sticky: as soon as you allow JetBrains to update IDEA, you've lost it.
The right way is to use Maven, but if there is a reason this cannot be done, here's how to add a library extra-Maven to the project.
You've been working on a number of projects in Eclipse, but wish to run IntelliJ and want them all open in the same window. They will be called modules.
Make certain that File → Settings → Appearance and Behavior → System Settings has either Open project in the same window or Confirm window to open project in clicked or opening new modules (projects) will happen in different windows. This would be fine, but the objective is to imitate Eclipse.
You should be able to see something as illustrated below with three modules (projects) each with src set as if File → Make Directory As → Sources Root and test as if File → Make Directory As → Test Sources Root were done.
Make certain that File → Settings → Appearance and Behavior → System Settings has either Open project in the same window or Confirm window to open project in clicked or opening/creating new projects or modules will happen in different windows.
First, create the project. The name will be the same as the sandbox and the location is the sandbox:
This gives you a new project in a new workbench window. You will see everything you're used to seeing when you list the sandbox' filesystem subdirectory. But, we're still not finished here! We have to make modules of the three, separate entities that were projects in Eclipse.
Depending on your project structure, you'll may also need to create a module of the dominant source-code parent subdirectory. (This sort of thing works very differently than in Eclipse. There are more notes on this, especially multimodule projects, below.)
What are projects under a same workbench in Eclipse are modules under a same project in IntelliJ IDEA.
For example, imagine a project, cda-filter, whose filesystem structure appears something like this:
cda-filter.v62_release.dev +-- cda-filter `-- run
Once this done, you can try to build (Build → Make Project). That might fail with either a message to set up a JDK (keep clicking, it will take you to Project Structure → Dependencies where you can set this up in Module SDK) and/or an obscure message about Maven, which you can fix also by clicking Maven Projects on the extreme right edge of the workbench window, then clicking the circular-arrow icon near the top of that pane. This should get you running. Beyond that, you're just fixing compilation errors, etc. before running.
This is a real example that may illustrate how to piece together an IntelliJ IDEA project with modules from an existing project (that used to be three Eclipse projects). The subprojects, that will become modules in IntelliJ, are psjbase, feeder and medical-filter, the last one being also the name of the greater or parent project (which changes versions in the illustrations—beware).
I started trying to use IntelliJ IDEA to work in the greater Feeder. In Eclipse, we're used to creating maybe a new workspace, but then importing, e.g.: buildscripts, feeder, medical-filter and psjbase into the workspace because that's what the "parent," e.g.: medical-filter.v62_release.dev, offers (among other things). This is not exactly how it happens in IntelliJ.
Follow the instructions in the preceding section for creating a new IntelliJ IDEA project.
Those three would be feeder, medical-filter and psjbase, of course. Sitting in the workbench with the new medical-filter.v62-release.dev project...
Do this for the other two, feeder and medical-filter.
For now, since we're not using Maven, the best way I can think of to solve the intermodule dependencies is the following. You'll do this for each of psjbase, feeder and medical-filter.
Setting up the Feeder's dependencies is a little precarious. First, psjbase, since everything else depends on it:
Next, feeder:
Last, medical-filter:
The up-shot of this is that I got it built with no red and could run a unit test, my old ApiTest.handleNewWithCommentsTest().
Please note that as a module is correctly configured, its name in the project window will become bold-faced. When it is no longer adequately configured, which may include having compilation errors created by incorrect configuration, it stops being bolded and often acquires a red underline. This goes away when it's well configured and working correctly.
This creates a project in the parent sandbox, medical-filter.v61_release.dev, and...
Once finished, you should see something like this (if not, check out errors below):
The nastiest error I have got when doing this is the following:
This refers to a problem in Project Structure → Modules again, under the Paths tab. It can be challenging to get it just right. Here are illustrations of how I configurated the output paths before the error going away:
One approach is to look at all the .iml files to see if they don't have the component's inherit-compiler-output set to false. Do this to figure that out:
~/sandboxes/medical-filter.v74_release.dev $ find . -name '*.iml' -exec fgrep -Hn NewModuleRootManager {} \; .code/psjbase/psjbase.iml: <component name="NewModuleRootManager" inherit-compiler-output="false"> .code/feeder/feeder.iml: <component name="NewModuleRootManager" inherit-compiler-output="false"> .code/medical-filter/medical-filter.iml: <component name="NewModuleRootManager" inherit-compiler-output="false"> ./medical-filter.v74_release.dev.iml: <component name="NewModuleRootManager" inherit-compiler-output="true">
You'll see a list; usually, the parent one will be set to true (go figure). Set the others to true as well, then do Build → Build Project.
Build → Build Project
If that doesn't work, try working with the Paths tab of each module or submodule:
I noted earlier that a correctly configured module will acquire a bold-faced name in the project window list. What follows here is most of the information, in addition to the immedidately previous section, needed to cause this to happen. It can be very tricky and require some patience.
Do these steps to configure other modules, libraries, JARs or subdirectories as dependencies.
...then, follow the appropriate steps described below for the type of dependency:
In this case, I've got to maintain a .idea outside the project. As it changes remotely (wherever I am working on this code from version control), I have to make a tarball of .idea and ship it along outside version control. I mention this because of the peculiar way this non-standard project is set up.
To test your new project/modules set-up, do Build → Make Project. If there are errors, a window should open across the bottom half of the workbench with references. Double-clicking the references will bring up the code files with the missing symbols. This should not be your experience as long as a) you followed the steps above and b) nothing has changed in the sample project that you must react to (like the addition of another JAR file to built.linux_x86-64).
To confirm, once you have a clean build, do Ctrl+Shift+Alt+N, type in "handleNewWithCommentsTest," then right-click on the highlighted method name and choose Run. The Run view should appear across the bottom half of the workbench telling you that this test case was successful.
Here is the finished configuation for consulting.
(So annoying...)
Go to File → Settings → Editor → Inspections → Java → Declaration redundancy → Declaration access can be weaker. Uncheck the box at the right.
File → Settings → Editor → Inspections → Java → Declaration redundancy → Declaration access can be weaker
Go to File → SEttings → Editor → Inspections → Java → Declaration redundancy → Actual method parameter is the same constant Uncheck the box at the right.
File → SEttings → Editor → Inspections → Java → Declaration redundancy → Actual method parameter is the same constant
Go to File → Settings → Editor → Inspections → Java → Class Structure → Field can be local. Uncheck the box at the right.
File → Settings → Editor → Inspections → Java → Class Structure → Field can be local
There are rare occasions where running Maven from the command line isn't what's happening inside IntelliJ. This situation is typically characterized by some strange goings-on in your project. For example, if you're using Google's addjars-maven-plugin to grab and statically link JARs from a subdirectory like lib, which IDEA hates, but Maven appears to tolerate, you're in for trouble and you have to use IntelliJ IDEA's Project Structure → Project Settings → Modules → Dependencies editor to make IDEA recognize symbols in those statically linked JARs.
You see a symbol from junit-x.y.jar missing inexplicably:
Beyond hope, you do File → Invalidate Cache / Restart to no avail. Then you inspect the module dependencies:
File → Invalidate Cache / Restart
Finally, you reinspect pom.xml and discover your stupid mistake:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
...only for it to dawn on you that the code consuming it isn't in fact test code when you've told Maven to restrict this JAR to the test scope.
...occurs when your IDEA module(s) is(are) ill-defined. You should not have src defined as Source, but the java subdirectory under main. Ditto for Test and the java subdirectory under test. The sign that this is problem is that you'll see errors for the package path(s), see indications that IntelliJ thinks that your package path is something like main.java.com.etc... when you meant it to be com.etc....
Chasing down a nasty problem of a missing method in slf4j-api, I needed to know who the culprit was that might be dragging in the wrong version of slf4j-api into the build.
I learned of adding
-verbose:class
...to the JVM arguments. In my case, this was happening in a JUnit test run. So I added this option by doing (in IntelliJ IDEA) Run → Edit Configurations... → JUnit. There I added, to VM options: this option. Then I ran the test. The option didn't take. I had to reedit the configuration, marking (under JUnit) the test run I was doing with the option. I'm not sure of the exact steps needed to do it correctly without playing with it, but it only took mea second try to get it right.
When I ran, the Run console window displayed huge amounts of data about classpath. I scraped this window, then edited the firs section of the scrape to put each JAR on its own line (splitting the lines on colon). Then, I grep'd the result for "slf4j."
Legend: below you see four sections.
master ~/notes $ fgrep slf4j debug-console.log :/home/russ/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar :/home/russ/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar :/home/russ/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar :/home/russ/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar [Loaded org.slf4j.LoggerFactory from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] [Loaded org.slf4j.ILoggerFactory from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] [Loaded org.slf4j.helpers.SubstituteLoggerFactory from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] [Loaded org.slf4j.Logger from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] [Loaded org.slf4j.spi.LoggerFactoryBinder from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] [Loaded org.slf4j.impl.StaticLoggerBinder from file:/home/russ/.m2/repository/com/etretatlogiciels/medical-filter/195/medical-filter-195.jar] [Loaded org.slf4j.helpers.MessageFormatter from file:/home/russ/.m2/repository/org/apache/tika/tika-app/1.0/tika-app-1.0.jar] java.lang.AssertionError: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple; Caused by: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
This put me on to the fact that Tika 1.0 may be hard-linking slf4j-api. And it would be the wrong (a very old) one too. Also, other lines tell me that, though I tried very hard to impose a version of 1.7.25 on slf4j, that's not what I'm getting. The culprits are, foremost, Tika and also medical-filter.
This is the possibility to set, not in any particular place in the code, but on an exception (or exceptions) occurring anywhere any time.
Beginning in late 2016 or early 2017, I started to get these messages. I'm still using the community edition because I can't find many reasons to upgrade. I feared that it might be for that reason and I submitted a problem (while it was still possible for an unlicensed/community-version user to do so), but didn't get a very helpful response.
I noticed that many others were complaining about this. There were various theories including ownership of or privileges in the relevant filesystem. Most of the inquiries were from Macintosh users so it wasn't really possible to investigate these claims or their presumed fixes. However, I kept thinking about the problem and once spied workspace.xml anomalies as a suggested cause.
Yesterday, I took a look at workspace.xml. It no longer existed in my projects. (Its home is under the .idea subdirectory.) I surmised that this had become the case somewhere along the way, perhaps originally because I had to use Bazaar for version control, and surely because this file holds settings more for the personal use of each developer than the use of all developers of the project code. So, I had excised it from Bazaar and somewhere along the way, it went missing entirely. Once we finally switched to Git, it remained a problem.
Clearly, I had expected this file to be maintained despite not being under version control. What I think led to its disappearance was, beginning to figure in .bzrignore (.gitignore), when a project is created/cloned anew, the file simply no longer exists. Moreover, as long as it doesn't exist, IDEA will not voluntarily create and begin to use it.
So, I touched this file ($ touch .idea/workspace.xml), then waited to see more of these warnings. I never did. This morning I came in to see that no warnings were issued during the night. To prove that the problem is fixed, it now has plenty in it (going from 0—a new, empty file, to a non-empty file).
To set up and use the Java disassembler directly from IntelliJ IDEA, as an external tool, do:
Name: javap Description: Java disassembler Program: /home/russ/dev/jdk1.8.0_144/bin/javap Arguments: -c $FileClass$ Working directory: $OutputPath$
/home/russ/dev/jdk1.8.0_144/bin/javap -c Error: no classes specified
This isn't so much fun. I'm a command-line kind of guy, but I'm looking for way for this to work in my IDE.
russ@nargothrond ~/dev/cassandra-lucene-index $ ~/dev/jdk1.8.0_144/bin/javap -s ./plugin/target/classes/com/stratio/cassandra/lucene/util/TaskQueue.class Compiled from "TaskQueue.scala" public interface com.stratio.cassandra.lucene.util.TaskQueue extends java.io.Closeable,com.stratio.cassandra.lucene.util.Logging { public static com.stratio.cassandra.lucene.util.TaskQueue build(int, int); descriptor: (II)Lcom/stratio/cassandra/lucene/util/TaskQueue; public abstract <A> void submitAsynchronous(java.lang.Object, scala.Function0<A>); descriptor: (Ljava/lang/Object;Lscala/Function0;)V public abstract <A> A submitSynchronous(scala.Function0<A>); descriptor: (Lscala/Function0;)Ljava/lang/Object; } russ@nargothrond ~/dev/cassandra-lucene-index $ ~/dev/jdk1.8.0_144/bin/javap -s \ ./plugin/target/classes/com/stratio/cassandra/lucene/util/TaskQueue$.class Compiled from "TaskQueue.scala" public final class com.stratio.cassandra.lucene.util.TaskQueue$ { public static com.stratio.cassandra.lucene.util.TaskQueue$ MODULE$; descriptor: Lcom/stratio/cassandra/lucene/util/TaskQueue$; public static {}; descriptor: ()V public com.stratio.cassandra.lucene.util.TaskQueue build(int, int); descriptor: (II)Lcom/stratio/cassandra/lucene/util/TaskQueue; }
At least by IDEA 2018, you might find a project that used to build no longer does. If the project has Scala in it, you may need to update the Scala plug-in:
If this doesn't work, open a Scala file. You should see a banner across the top saying, "No Scala SDK in module." Click Setup Scala SDK at the other end of the banner.
After this, the problem (e.g.: a missing imported symbol that's from Scala) should resolve itself or you can click in the IDE's right margin on Maven Projects, then on the circular arrows (for update).
Adding this to pom.xml one day in the project seemed to remedy it. In theory, this is how to ensure Java 8 in Maven build, but IDEA seems to pay attention too.
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
I had occasion to install on Windows 10 and start up. I did not want to have to reconfigure from scratch. I copied gondolin:/home/russ/.IntelliJIdea2018.1. Sucking that whole subdirectory over from gondolin is onerous given that I only needed some tiny subset, but what exactly is that subset?
I copied this subdirectory to Windows, so that it would be available to IDEA when starting up on Windows. It did not complain. Since this initial configuration came from so far away, I cleaned up the list of projects before creating a new project entitled, "untitled." I also updated the Python plug-in.
The analogous subdirectory (to .IntelliJIdea2018.1) on Windows appears to reside on the path C:\Users\rbateman\.IntelliJIdea2018.2—where IDEA puts it.
Check out Trisha Gee's article on Java 11 and IntelliJ IDEA.
Also, her article on the whole Java-version mess: Using Java 11 in Production: Important Things to Know.
Only in Ultimate version.
To reach it, do...
Ordinarily, in the Java editor, if there's an error or warning noted by a red or yellow bar down the right-hand margin of the editor, hovering over it will cause a red or yellow light-bulb to pop up over toward the left-hand margin next to the line with the error or warning. Clicking on that light-bulb gives one or more suggestions as to how best to proceed (fixes, etc.).
On Linux, I've had trouble sometimes getting the light-bulb corresponding to the error or warning I hover over or click on.
One solution that Jet Brains folk have put me on to is to click on the red or yellow bar in the right-hand margin, then press Alt+Enter. This will cause the light-bulb to appear.
The bar in the right-hand margin is purple here because I've already clicked on it before pressing Alt-Enter and IDEA changes it to that color.
A colleague commits and pushes crap and you're stuck with it or stuck spending a lot of time backing it out. How can you work to some extent while he's fixing it?
https://stackoverflow.com/questions/10851880/intellij-idea-run-code-regardless-of-errors-in-unrelated-project-files
This is remotely similar to another tool usable from Eclipse called ObjectAid™. A shallow illustration from my notes on that tool may be useful here in attempting to read these diagrams:
In the modules dialog, did you "over-recognize" sources? Is src blue as well as java under main or test?
Make only java under src/main blue as source code and java under src/test green as test code.
There is a default limit of 100 errors in IDEA's Messages: window in terms of how many errors out of javac it will display. This is a default in Sun's (Oracle's) compiler. To change this:
-Xmaxerrs 2000 -Xmaxwarns 2000
Yeah, I know. Who does this any more? And yet, I had to. Apart from having a good build.xml (see ant build.xml—a specific example), your test code will not be usable until you configure the module correctly. You'll get something like:
Process finished with exit code 1 Class not found: "com.acme.FunTest"
You must configure your module to use (especially) Test output path::
...as well as configuring your sources correctly and ensuring that the path elements, such as target here, exist in the filesystem:
First, think of leaving log4j.xml (log4j.properties) permanently in production configuration and on the path src/main/resources so that it's properly and accurately distributed.
Second, copy it to a new file that lives alongside it, log4j-development.xml. Modify this copy so that it does what you desire when developing including debugging, running JUnit tests, etc.
Next, in IntelliJ IDEA (this works in Eclipse too, but it's a slightly different path), go to Run → Edit Configurations... → Templates → JUnit and add this command-line definition to VM options: (see illustration below)
-Dlog4j.configuration=log4j-development.xml
By putting it in the JUnit templates, any JUnit run or debug definitions you create henceforth, when you run tests, will ensure that the JVM is run with this alternate log4j configuration instead of the production one. By putting it on JUnit under Templates, it will be automatically included every time you create a new JUnit run/debug configuration (and you will not have to add it there by hand each time).
For the least little reason, including recloning the project, you will lose this configuration.
See here.
This concerns the behavior of the editor (in Java) when I hold down the shift and control keys, then press right arrow. For example, I used to be able to place my cursor at the end of line 1 (below)
1 public void foo( int x ) 2 |{ 3 return x; 4 }
then do SHIFT+CTRL and press RIGHT-ARROW twice. The cursor would move to just BEFORE the opening curly brace selecting the newline. Now, however, it includes both the newline and the opening brace. Similarly, beginning after the opening brace, if I do SHIRT+CTRL and press RIGHT-ARROW twice, it goes to include the word return.
The solution is to go to File → Settings → Editor → General. Where you see Caret Movement, for When moving by works:, change to Always jump to word start.
See IntelliJ IDEA: move caret to end of word.
The IDE's Build reports that the compiler cannot find a class despite that a) there's no red ink inside the editor for the (many) classes missing it, b) the symbol is clearly present.
Every consuming class reports this missing symbol. I have invalidated cache and restarted several times. This just began happening in the IDE; it does not happen from the command line (mvn clean test).
I was successful rebuilding the project, Build → Rebuild .
Simpler, more functional, useful and certainly far more stable than the Eclipse-only ObjectAid is a UML-diagram plug-in that is available in the Ultimate (but not the Community) Edition that displays class hierarchy by package.
You can right-click in the open (uninhabited) field of the Editor window to get a context menu to affect...
You can edit individual nodes by right-clicking on them to get a context menu to...
You can select nodes by clicking or shift-clicking.
It's possible to add the diagram to version-control for later use, print it, save it as an image, etc. Most everything you would want to do is provided for.
Find the diagram window top bar in the Editor and click its close box.
@SuppressWarnings( "SpellCheckingInspection" ) // for whole class public class Class { @SuppressWarnings( "SpellCheckingInspection" ) // for just the method private void method() { // noinspection SpellCheckingInspection // for just the statement one statement; } }
IntelliJ IDEA assumes that HTML and XML aren't something you craft, but something you start typing at the beginning and don't stop until you reach the end.
Go to File → Settings → Editor → General → Smart Keys → HTML/CSS. Uncheck the following:
This doesn't sort out the crazy indentation IDEA forces upon you. That's going to be a separate problem. Later, however, Leija Chen of JetBrains suggested...
Go to File → Settings → Editor → Code Style → HTML → Indent.
This finally sorts out the editor's over-zealous supervision of my HTML code.
This is a JDK feature, I believe, that IntelliJ IDEA accommodates—not one that it implements. You can get jshell from the console command line (outside IntelliJ IDEA) if you have Java (>= 9) installed.
int x = 503; System.out.println( x / 100 );
Defined field int x = 503 System.out.println( x / 100 ) 5
When you type a new classname as you code, one that isn't known, IDEA proposes myriad possibilities including stupid ones (because, how could it know?).
You can't really stop this, though it would be nice to make a list of the dumber ones so you never see them or fat-finger unintentionally. The best you can do is:
This produces a list of questions (issues, "how-to"): https://intellij-support.jetbrains.com/hc/en-us/requests
This is a tracking of issues (proposed bugs, I think) by you. You must change your name: https://youtrack.jetbrains.com/issues?q=reported%20by:%20russellbateman
I have had a devil of a time getting these right. What goes on is that, even after getting web.xml and any Java service code (@Path(), etc.) correct, running Tomcat from IDEA always results in HTTP Status 404. Pull hair out!
Usually, if I deploy my application to Tomcat, it works fine, but this is no way to be able to debug it.
The trick is getting the Run/Debug Configuration correct. The two critical fields (other stuff can go wrong, but for the 404, this is what's usually wrong) are Server → URL and Deployment → Application context:.
A better, probably clearer, explanation can be found by reading Simple Web Application, Set up Tomcat and Toubleshooting the inevitable HTTP Status 404.
...for the project. Is it on a network drive?
...or...
The current inotify(7) watch limit is too low.
Create this file and stuff it with the following content, then restart using the command shown:
# vim /etc/systctl.d/60-jetbrains.conf ------------------------------------------------------------------------------------------------ # Set inotify watch limit high enough for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm). # Create this file as /etc/sysctl.d/60-jetbrains.conf (Debian, Ubuntu), and # run `sudo service procps start` or reboot. # Source: https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit # # More information resources: # -$ man inotify # manpage # -$ man sysctl.conf # manpage # -$ cat /proc/sys/fs/inotify/max_user_watches # print current value in use fs.inotify.max_user_watches = 524288 ------------------------------------------------------------------------------------------------ # sysctl -p --system
Note that this discussion holds for running JUnit tests in IntelliJ IDEA; this problem would not appear when running the build (and executing JUnit tests suffering this problem) from the command line thus:
$ mvn clean package
Consider getting an error from attempting to run or debug this code. You can copy and paste this code to your JUnit test suite (class). Pick a filename that suits you. (Run this code to duplicate the eponymous error noted here.)
@Test public void test() throws IOException { final String FILENAME = "95004.xml"; final String RELATIVE = "src/test/resources/fodder/" + FILENAME; final String ABSOLUTE = "/home/russ/sandboxes/project/src/test/resources/fodder/" + FILENAME; File file = new File( RELATIVE ); System.out.println( " Path: " + file.getPath() ); System.out.println( " Absolute Path: " + file.getAbsolutePath() ); System.out.println( "Canonical Path: " + file.getCanonicalPath() ); System.out.println( " Can read: " + file.canRead() ); System.out.println( " Can write: " + file.canWrite() ); System.out.println( " Can execute: " + file.canExecute() ); try { FileInputStream inputStream = new FileInputStream( file ); } catch( FileNotFoundException e ) { System.err.println( e.getMessage() ); e.printStackTrace(); } }
Now, follow these steps to see why this bug exists.
Path: src/test/resources/fodder/95004.xml Absolute Path: /home/russ/sandboxes/src/test/resources/fodder/95004.xml Canonical Path: /home/russ/sandboxes/src/test/resources/fodder/95004.xml Can read: false Can write: false Can execute: false src/test/resources/fodder/95004.xml (No such file or directory) java.io.FileNotFoundException: src/test/resources/fodder/95004.xml (No such file or directory) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at com.windofkeltia.validation.ValidationTest.test0(ValidationTest.java:60)
Path: src/test/resources/fodder/95004.xml Absolute Path: /home/russ/sandboxes/ccd-validator/src/test/resources/fodder/95004.xml Canonical Path: /home/russ/sandboxes/ccd-validator/src/test/resources/fodder/95004.xml Can read: true Can write: true Can execute: false
That is, from a JUnit test. There is no way to do this except to use stderr:
System.err.print ( "This text will come out in red, but" ); System.out.println( "this text comes out in normal black." );
...will produce this:
This text will come out in red, but this text comes out in normal black.
This could sometimes be just useful enough to justify going to the trouble to do it. However, race conditions may result in the two hitting the console out of order!
To open a Java file that's in the current project, one does Ctrl-N and a list of all project files appears and finding yours is aided by a short-stroke mechanism.
However, this doesn't get you, for example, logback.xml or that test fodder you last put on the path src/test/resources/fodder, etc.
To get non-Java files, you must do Ctrl-N, then hit the Shift key twice, which is the same thing as clicking on the All tab at the upper left of the dialog.
Another incantation is Ctrl+Shift+N which gives you the dialog with the File tab. This action is the same thing as pulling down the Navigate menu and selecting File... .