Create jar File from IntelliJ or Eclipse

Hi

I’m new on Java and ItelliJ. I have downloaded IntelliJ because I use phpStorm from the same company and known the interface. I work on Windows 10. My OpenHab is on a Debian machine.
I have also try eclipse.

My goal is to change a small passage of a binding.

At first, I have downloaded the master ZIP File from git: https://github.com/volfan6415/openHAB-EMBY

IntelliJ: I go to File - Open and use pom.xml. At first I will only try if I can create the .jar file before I change the code. When I go to Build - Build Project I get this error:

Error:java: error: release version 5 not supported
I have installed the zulu 8 jdk

In eclipse the same. I open the project, go to File - Export and JAR file. Here I use all files in org.openhab.binding.emby, and chose this options:

The error is

JAR export finished with warnings. See details for additional information.
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyBindingConstants.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyHandlerFactory.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/discovery/EmbyClientDiscoveryService.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/discovery/EmbyDiscoveryService.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/handler/EmbyDeviceHandler.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/handler/EmbyBridgeHandler.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/embyPlayState.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyPlayStateModel.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyPlayingPostJsonModel.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/nowPlayingItem.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyConnection.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyClientSocket.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyDeviceEncoder.java
  Exported with compile errors: org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyHTTPUtils.java

I think I forgot to load anything. Does someone can help me to export the jar file?

As this is a maven project you cannot just click Build > Build Project in IntelliJ. You need to tell it to use maven to build.

You can do this in two ways:

  1. The maven tool window (easiest for a one-off build)
  2. A run configuration (easiest for repeated use)

Maven Tool Window

  1. Click on the “Maven” button on the right side of your window or go to View > Tool Windows > Maven
  2. In the “Maven” window double click [your project] > Lifecycle > install
  3. Look for JAR in [your project dir]/target

Run Configuration

  1. Click the run configuration drop-down on the top toolbar (between the “hammer” and “play” buttons)
  2. Select “Edit Configurations…”
  3. Click the plus button in the top left of the new window
  4. Select “maven”
  5. Give your run configuration a name.
  6. Pick your working directory
  7. Put clean install in the “command line” field.
  8. Press “OK”
  9. Select your new run configuration from the drop-down on the top toolbar.
  10. Press the run (“play”) button to the right of the drop-down.
  11. Look for JAR in [your project dir]/target
1 Like

@rossgb: Thank you for your great tutorial. I have set this, but IntelliJ search a parent POM

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for org.openhab.addons.bundles:org.openhab.binding.emby:2.5.0-SNAPSHOT: Could not find artifact org.openhab.addons.bundles:org.openhab.addons.reactor.bundles:pom:2.5.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 11
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project org.openhab.addons.bundles:org.openhab.binding.emby:2.5.0-SNAPSHOT (D:\Profil\Downloads\openHAB-EMBY-master\openHAB-EMBY-master\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for org.openhab.addons.bundles:org.openhab.binding.emby:2.5.0-SNAPSHOT: Could not find artifact org.openhab.addons.bundles:org.openhab.addons.reactor.bundles:pom:2.5.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help 2]
[ERROR]

Someone with a better grasp on the build system may be able to help you with a more elegant solution when you are not working with a full fork of openhab-addons.

This should at least get you building:

  1. Clone / Download the openhab-addons repo: https://github.com/openhab/openhab-addons
  2. Put your openHAB-EMBY project in <openhab-addons>/bundles/org.openhab.binding.emby
  3. Add this inside the <modules> section in <openhab-addons>/bundles/pom.xml:
<module>org.openhab.binding.emby</module>
  1. Add this inside the <dependencies> section of <openhab-addons>/bom/openhab-addons/pom.xml:
<dependency>
  <groupId>org.openhab.addons.bundles</groupId>
  <artifactId>org.openhab.binding.emby</artifactId>
  <version>${project.version}</version>
</dependency>
  1. Inside <openhab-addons>/bundles/org.openhab.binding.emby/pom.xml change this:
<version>2.5.0-SNAPSHOT</version> 

to this:

<version>2.5.5-SNAPSHOT</version> 

Thank you @rossgb and please excuse the initial questions. I must Change a few think but it works :slight_smile:

If you have time, you can also explain to me how I work with a full fork. Who knows if I won’t try my own bindings later. But this is not urgent :slight_smile:

By a “full fork” I just meant that you can create a new binding project by forking the entire openhab-addons repo and write your binding in-place (as I told you to re-create in my previous post). This makes building easier as maven can find parent POMs by just looking at parent directories.

In this openHAB-EMBY project only the binding itself is checked into the git repo. This means maven needs to go looking elsewhere for parent POMs.
I’m sure there are some arguments you can pass to maven to tell it to look somewhere else in the filesystem or in a maven repository but I’ve not tried that before so I just told you the way I know works.

1 Like

Hi

Sorry I have an additional question. Givs an option in IntelliJ do cleanup the folder?

After I generate the jar file, I have many files like .importorder, .prefs or two times the thing-types.xml (one in target, classes, ESH-INF, thing
and one in src, main, ressources, ESH-INF, thing

Or givs some folder where I can delete after generate?

The maven “clean” phase will get rid of that for you.

e.g. in the maven tool window: [your project] > Lifecycle > clean

Just make sure you do not have any files from the “target” directory open or maven may not be able to clean everything.