Instructions:
File → Project Structure → Project Settings → Artifacts → Click + (plus sign) → Jar → From modules with dependencies...
Select a Main Class (the one with main() method) if you need to make the JAR file runnable.
Select Extract to the target Jar
Click OK
Click Apply/OK
The above sets the "skeleton" to where the JAR file will be saved to. To actually build and save it do the following:
Build → Build Artifact → Build
Try Extracting the .jar file from:
📦ProjectName
┗ 📂out
┗ 📂artifacts
┗ 📂ProjectName_jar
┗ 📜ProjectName.jar
References:
- (Aug 2010) Quickly create a JAR artifact for an application (Here's how to build a JAR file with IntelliJ IDEA 10)
- (Mar 2023) Package an application into a JAR
Normally when compiling with kotlinc it outputs something. For example, if i compiled "kotlin.kt" it would output a kotlin.jar file
But I just hit the build button in IntelliJ and it built successfully but where is my executable file going? Or how can I find out where it is outputting it?
java - How can I build JAR files from IntelliJ IDEA properly? - Stack Overflow
How to show build directory in IntelliJ IDEA - Stack Overflow
Intellij IDEA: How to change build directory? - Stack Overflow
How do you work with IntelliJ IDEA and sbt?
I agree that the default Intellij Scala experience isn't as nice as it can be. There are two big big directions you can go to make it a lot nicer:
Currently I find myself switching between these two methods depending on what I'm doing
Below instructions assume Intellij 2020.1 or later
Use SBT Shell
Instructions:
-
Open the project as a SBT project
-
In
File | Settings | Build, Execution, Deployment | Build Tools | sbt, tick all ofDownload- 'Library Sources', 'SBT sources' andUse SBT shell'for imports', 'for builds' -
Refresh the project
You should see a SBT shell tool window with an embedded SBT running inside. If you try to compile the project (Ctrl-F9) you'll see that SBT is doing the compile.
You can click on any of the compile errors and then press Ctrl-Shift-Up/Down to navigate between errors (much like how you navigate between search results). Just note that you need to click on one error first before the hotkeys will work
Pros:
-
Keeps compiler hot
-
Can run SBT tasks without starting a separate SBT
Cons:
-
Errors are hard to read
-
No SBT completion
-
Sometimes killing the SBT shell doesn't kill the process
Bloop & BSP
BSP / Bloop stability has improved significantly since 2020.1 and I've been pretty happy with it
Instructions:
-
Delete
.ideaand useFile | Opento open your project. ChooseBSPproject when asked -
You should see
I personally turn off 'File | Settings | Build, Execution, Deployment | Build Tools | BSP | export SBT projects to bloop before import' and choose to run sbt bloopImport myself as I often have SBT running anyway
Pros:
-
Faster compiles
-
Better compile error UI (more integrated than just a console window)
-
You can run tests in watch mode in another terminal window and the compilation is automatically deduplicated
Cons:
-
Need to start SBT to run anything other than compile / test (e.g. coverage)
-
No IDE help when editing
build.sbt
Why not both
This is my script to switch between BSP and SBT project
#! /bin/bash
# Switch Intellij projects from sbt to bsp (and vice versa)
if [[ -d .idea ]]
then
if [[ -d .ideas ]]
then
mv .idea .ideab && mv .ideas .idea
elif [[ -d .ideab ]]
then
mv .idea .ideas && mv .ideab .idea
else
# Preparing for bsp project
mv .idea .ideas
fi
fi More on reddit.com Instructions:
File → Project Structure → Project Settings → Artifacts → Click + (plus sign) → Jar → From modules with dependencies...
Select a Main Class (the one with main() method) if you need to make the JAR file runnable.
Select Extract to the target Jar
Click OK
Click Apply/OK
The above sets the "skeleton" to where the JAR file will be saved to. To actually build and save it do the following:
Build → Build Artifact → Build
Try Extracting the .jar file from:
📦ProjectName
┗ 📂out
┗ 📂artifacts
┗ 📂ProjectName_jar
┗ 📜ProjectName.jar
References:
- (Aug 2010) Quickly create a JAR artifact for an application (Here's how to build a JAR file with IntelliJ IDEA 10)
- (Mar 2023) Package an application into a JAR
This is still an issue in 2017. I hope it will help somebody out there!
I found two possibilities to create working JAR files under IntelliJ 2017.2
1. Creating an artifact from IntelliJ:
- Go to project structure:

- Create a new artifact:

- Select the main class, and be sure to change the manifest folder:

You have to change manifest directory:
<project folder>\src\main\java
Replace "java" with "resources"
<project folder>\src\main\resources
This is how it should look like:

Then you choose the dependencies what you want to be packed in your JAR file, or near your JAR file
To build your artifact, go to build artifacts and choose "rebuild". It will create an "out" folder with your JAR file and its dependencies.

2. Using maven-assembly-plugin
Add a build section to the POM file
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>ServiceCreate</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.svt.optimoo.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
- Create a new run/debug configuration:

- Choose an application:

- Fill in the form
- Add the "assembly:single" Maven goal after the build to be executed last


- Save it, and then run

This procedure will create the JAR file under the "target" folder

Maybe your build directory is marked as "Excluded". Go to Project Settings -> Modules -> your module. Remove "Excluded" mark from your build directory.

Then modules->

You could overwrite the exclude of the build directory (see IdeaModule in the Gradle Build Language Reference for details). However, from what I remember, this will slow down IntelliJ, give duplicates in file searches, etc. Hence, it may not be a good solution to whatever problem you are ultimately trying to solve.
You can find the setting here
File [Menu] > Project Structure > Modules [List] > Path [Tab] > Use module compile output path [Option]
In Intellij IDEA 13.1.4, do:
- File [menu]
- Project Structure [option]
- Project Settings [section]
- Project [tab]
- Project compiler output [text field]