Browsed by
Tag: intellij

Path environment variable at IntelliJ on macOS

Path environment variable at IntelliJ on macOS

intellij-ideaLately I encountered a problem with IntelliJ on macOS I wasn’t aware of so far. For a new project I joined it was necessary to let Java execute a shell script which resides in /usr/local/bin and calls another script. Putting all the questions for the reason behind this aside I was pretty puzzled when I couldn’t get this to work while on all my colleagues Linux machines it worked like a charm.
After fiddling around with it for a while it became very much clear that the JVM which I started from IntelliJ didn’t had /usr/local/bin in its PATH environment variable and because of that couldn’t execute the script. The question was why this was the case. When I started the application via gradle on the shell everything worked correct which seemed to point to an IntelliJ problem. After some research it became clear that the root cause of the problem is a concept in macOS which separates the shell environment variables from the environment variables for GUI processes, or better said the environment variables for processes which are started from Spotlight, Finder or the desktop.
The standard environment variables set for GUI applications on macOS are controlled via launchctl and are per default set to /usr/bin:/bin:/usr/sbin:/sbin.

The quick solution to get around this and use the environment variables set in the Shell via .bashrc or .zshrc etc. is to start IntelliJ (or any other UI application) via the command line. This can be done on with the command

open /Applications/IntelliJ\ IDEA.app

After that IntelliJ runs in the shell context and has access to all the variables set there. If this doesn’t suit you and you want a more permanent solution which makes it possible to start IntelliJ without the shell and still have access to the environment variables there is a solution for that, too.
You have to create the file ~/Library/LaunchAgents/environment.plist. A plist file in macOS is a property list file which is a widely used concept in macOS (read more about it here). In this file there can be some startup configurations stored. A minimal configuration to just control the environment variables could look like this:

Read More Read More

Dynamic switching dev and prod datasource with maven profiles

Dynamic switching dev and prod datasource with maven profiles

maven logo
Most of the time when you develop an application that uses a database you are likely to use another database for your local development work than what you will use later in production. The main reason for this is that there are databases like H2 which by design are fitting the development situation while they are not very well suited for production usage. H2 i.e. has very fast startup times, can run completely in memory -this is an advantage because every time it is restarted its state is reset, too-, uses only few system resources and has a good mySQL compatibility. On the other hand it is not that popular in production as it lacks many functionalities like custom functions, an SQL interpreter etc.. Following this it is a very common scenario to use mySQL in production while using H2 for development. This way the developer can use the same database dialect for development while the local installation of a mySQL DB is not needed.
The problem with this scenario is that you need to switch the datasource to production when you build a new release and switch back to development when you want to use your local H2 for testing. This is something which can easily be forgotten and become annoying over time. Therefore it is a step which could and should be automated.
When you are using JavaEE you define your datasource depending on the application server either via an interactive tool (i.e. glassfish or payara via the asadmin command) or in a xml file (i.e. wildfly/jboss standalone.xml or TomEE context.xml). As an example I show you here a valid datasource definition in the wildly standalone.xml

<subsystem xmlns="urn:jboss:domain:datasources:4.0">
  <datasources>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
      <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
        <driver>h2</driver>
        <security>
          <user-name>sa</user-name>
        </security>
      </datasource>

      <datasource jndi-name="java:jboss/datasources/ExampleMySQLDS" pool-name="ExampleMySQLDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:mysql://localhost:3306/brachub</connection-url>
        <driver>mysql</driver>
        <security>
            <user-name>root</user-name>
            <password>1234</password>
        </security>
        <statement>
            <prepared-statement-cache-size>100</prepared-statement-cache-size>
            <share-prepared-statements>true</share-prepared-statements>
        </statement>
    </datasource>

    <drivers>
      <driver name="h2" module="com.h2database.h2">
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
      </driver>
      <driver name="mysql" module="com.sql.mysql">
        <driver-class>com.mysql.jdbc.Driver</driver-class>
      </driver>
    </drivers>
  </datasources>
</subsystem>

Read More Read More

Solution for the IntelliJ issue on macOS Sierra

Solution for the IntelliJ issue on macOS Sierra

intellij-idea
Jetbrains has come up with a solution for the scrolling problem with IntelliJ IDEA based IDEs under macOS Sierra. They released a modified JDK8 which hast to be set as boot JDK for IntelliJ. You can download the JDK here.
For setting it as the boot JDK you need to got to action menu. This is reached under macOS by pressing ⌘ + ⇧ + a (in other words cmd + shift + a) buttons and entering in the search box the term “switch IDE boot JDK”.
intellij-switch-jdk
The new JDK will be part of the next stable release of IntelliJ and is actually available as part of the 2016.3 EAP.
As this seems to fix the scrolling issue there are still reports of problems with the context click behavior.

Scrolling issue with macOS Sierra and IntelliJ IDEA [UPDATE]

Scrolling issue with macOS Sierra and IntelliJ IDEA [UPDATE]

intellij-idea
If you rely on IntelliJ (or any other IDE based on the IntelliJ platform like WebStorm i.e.) for your daily work and use a touchpad (no matter if the Macbook internal or the magic trackpad) you should not upgrade to Sierra at the moment. The issue is that the scrolling behavior in IntelliJ is extremely sensitive which makes a controlled scrolling nearly impossible. IntelliJ seems to doesn’t know of a way to fix this at the moment and filed itself a radar at Apples bug tracker. As you can find complains from users of other Apps with the same problem as well (VLC and Minecraft i.e.) it seems plausible that the ball on this is in Apples field.

As Jetbrains obviously have done nothing wrong with its implementation to trigger this issue it would have been a good move from them to address the issue to their customers early (previous to the sierra release) so that they could have waited with the macOS upgrade until the problem is solved. If you are interested you can find a discussion about the problem at their bug tracker.

Not knowing how long it will take Apple or Jetbrains to solve the issue the easy workaround for the users is using a mouse as it affects the trackpad only. I use the magic mouse but every other mouse should work fine, too.

Update 03.10.16

Jetbrains has come up  with a solution for the problem which you can find here