Intellij make jar

Intellij make jar DEFAULT

Create your first Java application

In this tutorial, you will learn how to create, run, and package a simple Java application that prints to the system output. Along the way, you will get familiar with IntelliJ IDEA features for boosting your productivity as a developer: coding assistance and supplementary tools.

Watch the screencast and follow the step-by-step instructions below:

Prepare a project

Create a new Java project

In IntelliJ IDEA, a project helps you organize your source code, tests, libraries that you use, build instructions, and your personal settings in a single unit.

  1. Launch IntelliJ IDEA.

    If the Welcome screen opens, click New Project.

    Otherwise, from the main menu, select .

  2. In the New Project wizard, select Java from the list on the left.

  3. To develop Java applications in IntelliJ IDEA, you need the Java SDK (JDK).

    If the necessary JDK is already defined in IntelliJ IDEA, select it from the Project SDK list.

    If the JDK is installed on your computer, but not defined in the IDE, select and specify the path to the JDK home directory (for example, /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk).

    Creating the new project and adding the JDK

    If you don't have the necessary JDK on your computer, select . In the next dialog, specify the JDK vendor (for example, OpenJDK), version, change the installation path if required, and click Download.

    Downloading a JDK when creating a project
  4. We're not going to use any additional libraries or frameworks for this tutorial, so click Next.

  5. Don't create a project from the template. In this tutorial, we're going to do everything from scratch, so click Next.

  6. Name the project, for example: .

  7. If necessary, change the default project location and click Finish.

Create a package and a class

Packages are used for grouping together classes that belong to the same category or provide similar functionality, for structuring and organizing large applications with hundreds of classes.

  1. In the Project tool window, right-click the src folder, select New (or press ), and then select Java Class.

  2. In the Name field, type and click OK.

    IntelliJ IDEA creates the package and the class.

Together with the file, IntelliJ IDEA has automatically generated some contents for your class. In this case, the IDE has inserted the package statement and the class declaration.

This is done by means of file templates. Depending on the type of the file that you create, the IDE inserts initial code and formatting that is expected to be in all files of that type. For more information on how to use and configure templates, refer to File templates.

The Project tool window displays the structure of your application and helps you browse the project.

In Java, there's a naming convention that you should follow when you name packages and classes.

Write the code

Add the main() method using live templates

  1. Place the caret at the class declaration string after the opening bracket and press .

    In contrast to , starts a new line without breaking the current one.

  2. Type and select the template that inserts the method declaration.

    As you type, IntelliJ IDEA suggests various constructs that can be used in the current context. You can see the list of available live templates using .

Live templates are code snippets that you can insert into your code. is one of such snippets. Usually, live templates contain blocks of code that you use most often. Using them can save you some time as you don't have to type the same code over and over again.

For more information on where to find predefined live templates and how to create your own, refer to Live templates.

You can also add the statement using the live template.

Call the println() method using code completion

After the method declaration, IntelliJ IDEA automatically places the caret at the next line. Let's call a method that prints some text to the standard system output.

  1. Type and select the class from the list of code completion suggestions (it's from the standard package).

    Press to insert the selection with a trailing comma.

  2. Type , select , and press again.

  3. Type , select the println(String x) method, and press .

    IntelliJ IDEA shows you the types of parameters that can be used in the current context. This information is for your reference.

  4. Type . The second quotation mark is inserted automatically, and the caret is placed between the quotation marks. Type

Basic code completion analyses the context around the current caret position and provides suggestions as you type. You can open the completion list manually by pressing .

For information on different completion modes, refer to Code completion.

Build and run the application

Valid Java classes can be compiled into bytecode. You can compile and run classes with the method right from the editor using the green arrow icon the Run the Remove button in the gutter.

  1. Click the Run the Remove button in the gutter and select Run 'HelloWorld.main()' in the popup. The IDE starts compiling your code.

  2. When the compilation is complete, the Run tool window opens at the bottom of the screen.

    The first line shows the command that IntelliJ IDEA used to run the compiled class. The second line shows the program output: . And the last line shows the exit code , which indicates that it exited successfully.

    If your code is not correct, and the IDE can't compile it, the Run tool window will display the corresponding exit code.

When you click Run, IntelliJ IDEA creates a special run configuration that performs a series of actions. First, it builds your application. On this stage, javac compiles your source code into JVM bytecode.

Once javac finishes compilation, it places the compiled bytecode to the out directory, which is highlighted with yellow in the Project tool window.

After that, the JVM runs the bytecode.

Automatically created run configurations are temporary, but you can modify and save them.

If you want to reopen the Run tool window, press .

IntelliJ IDEA automatically analyzes the file that is currently opened in the editor and searches for different types of problems: from syntax errors to typos. The Inspections widget at the top-right corner of the editor allows you to quickly see all the detected problems and look at each problem in detail. For more information, refer to Current file.

Package the application in a JAR

When the code is ready, you can package your application in a Java archive (JAR) so that you can share it with other developers. A built Java archive is called an artifact.

Create an artifact configuration for the JAR

  1. From the main menu, select File | Project Structure and click Artifacts.

  2. Click the Add button, point to JAR and select From modules with dependencies.

  3. To the right of the Main Class field, click the Browse button and select HelloWorld (com.example.helloworld) in the dialog that opens.

    IntelliJ IDEA creates the artifact configuration and shows its settings in the right-hand part of the Project Structure dialog.

  4. Apply the changes and close the dialog.

Build the JAR artifact

  1. From the main menu, select Build | Build Artifacts.

  2. Point to HelloWorld:jar and select Build.

    Building an artifact

    If you now look at the out/artifacts folder, you'll find your JAR there.

    The JAR artifact is built

Run the packaged application

To make sure that the JAR artifact is created correctly, you can run it.

Use Find Action to search for actions and settings across the entire IDE.

Create a run configuration for the packaged application

To run a Java application packaged in a JAR, IntelliJ IDEA allows you to create a dedicated run configuration.

  1. Press , find and run the Edit Configurations action.

  2. In the Run/Debug Configurations dialog, click the Add button and select JAR Application.

  3. Name the new configuration: .

    Creating a new run configuration
  4. In the Path to JAR field, click the Browse button and specify the path to the JAR file on your computer.

  5. Scroll down the dialog and under Before launch, click the Add button, select in the dialog that opens.

    Doing this means that the HelloWorld.jar is built automatically every time you execute this run configuration.

    Specifying path to JAR file

Run configurations allow you to define how you want to run your application, with which arguments and options. You can have multiple run configurations for the same application, each with its own settings.

Execute the run configuration

  • On the toolbar, select the configuration and click the Run button to the right of the run configuration selector. Alternatively, press if you prefer shortcuts.

    As before, the Run tool window opens and shows you the application output.

Running the packaged application

The process has exited successfully, which means that the application is packaged correctly.

Last modified: 05 October 2021

Overview of the user interfaceIntelliJ IDEA keyboard shortcuts

Sours: https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html

Example

Eventually, when you're ready to release a version of your code to production, you'll need a file to distribute. Intellij makes building JARs quite easy.

First, navigate to and click on : Artifacts

Click on the button, and select : enter image description here

Select your module from the dropdown list, and the main file (this is the file that contains your method): enter image description here

Click , verify that all the information regarding dependencies is correct, and click to finish setting up the artifact. enter image description here

We're not done yet! We've only told Intellij how to build the artifact, now we actually need to make the .

Simply click , and click on the popup menu: enter image description here

The will be found in






Previous Next

Sours: https://riptutorial.com/intellij-idea/example/16922/building-a--jar
  1. Chalmers apartments detroit mi
  2. Us tv tropes
  3. Air georgian review
  4. Wholesale jelly purses
  5. Sad lonely gif

Compile and build applications with IntelliJ IDEA

The IntelliJ IDEA compilation and building process compiles source files and brings together external libraries, properties files, and configurations to produce a living application. IntelliJ IDEA uses a compiler that works according to the Java specification.

You can compile a single file, use the incremental build for a module or a project, and rebuild a project from scratch.

If you have a pure Java or a Kotlin project we recommend that you use IntelliJ IDEA to build your project since IntelliJ IDEA supports the incremental build which significantly speeds up the building process.

However, IntelliJ IDEA native builder might not correctly build the Gradle or Maven project if its build script file uses custom plugins or tasks. In this case, the build delegation to Gradle or Maven can help you build your project correctly.

Compile a single file or class

  • Open the needed file in the editor and from the main menu, select ().

    Alternatively, in the Project tool window, right-click the class you need and from the context menu, select Recompile 'class name'.

    If errors occur during the compilation process, IntelliJ IDEA will display them in the Review compilation and build output along with warning messages.

Change the compilation output locations

When you compile your source code, IntelliJ IDEA automatically creates an output directory that contains compiled .class files.

Compile output directory

Inside the output directory, IntelliJ IDEA also creates subdirectories for each of your modules.

The default paths for subdirectories are as follows:

  • Sources:<ProjectFolder>/out/production/<ModuleName>

  • Tests:<ProjectFolder>/out/test/<ModuleName>

At the project level, you can change the <ProjectFolder>/out part of the output path. If you do so (say, specify some <OutputFolder> instead of <ProjectFolder>/out) but don't redefine the paths at the module level, the compilation results will go to <OutputFolder>/production/<ModuleName> and <OutputFolder>/test/<ModuleName>.

At the module level, you can specify any desirable compilation output location for the module sources and tests individually.

Specify compilation output folders

  1. Open the Project Structure dialog (File | Project Structure).

  2. In Project Settings, select Project and in the Project compiler output field, specify the corresponding path.
    Project Structure dialog / Projects page

    For modules, select Modules, the module you need and the Paths tab. Change the location of the output folder under the Compiler output section.

    Project Structure dialog / Module page

Build

When you execute the Buildthe Build Project icon command, IntelliJ IDEA compiles all the classes inside your build target and places them inside the output directory.

When you change any class inside the build target and then execute the build action, IntelliJ IDEA performs the incremental build that compiles only the changed classes. IntelliJ IDEA also recursively builds the classes' dependencies.

Build a module, or a project

  • Select a module or a project you want to compile and from the main menu, select ().

    IntelliJ IDEA displays the compilation results in the Review compilation and build output.

If you add a module dependency to your primary module and build the module, IntelliJ IDEA builds the dependent module as well and displays it in the output directory alongside the primary one. If the dependent module has its own module dependencies, then IntelliJ IDEA compiles all of them recursively starting with the least dependent module.

Project Structure dialog / Module page

The way the module dependencies are ordered may be very important for the compilation to succeed. If any two JAR files contain classes with the same name, the IntelliJ IDEA compiler will use the classes from the first JAR file it locates in the classpath.

For more information, see Module dependencies.

Rebuild

When you execute a rebuild command, IntelliJ IDEA cleans out the entire output directory, deletes the build caches and builds a project, or a module from scratch. It might be helpful, when the classpath entries have changed. For example, SDKs or libraries that the project uses are added, removed or altered.

Rebuild a module, or a project

When the Rebuild Project action is delegated to Gradle or Maven, IntelliJ IDEA doesn't include the task/goal when rebuilding a project. If you need, you can execute the command before the rebuild using the Execute Before Rebuild option in the Gradle or Maven tool window.

Background compilation (auto-build)

You can configure IntelliJ IDEA to build your project automatically, every time you make changes to it. The results of the background compilation are displayed in the Problems tool window.

Configure the background compilation

  1. Press to open the IDE settings and select Build, Execution, Deployment | Compiler.
  2. On the Compiler page, select Build project automatically.

    Now when you make changes in the class files, IntelliJ IDEA automatically performs the incremental build of the project.

    The automatic build also gets triggered when you save the file () or when you have the Save files automatically if application is idle for N sec. option selected in the System settings dialog.

Enabling the Build project automatically option also enables Build project in

When you have the Power Save Mode option () enabled in your project, the auto-build action is disabled, and you need to manually run the build ().

Compile before running

By default, when you run an application, IntelliJ IDEA compiles the module where the classes you are trying to run are located.

If you want to change that behavior, you can do so in the Run/Debug Configurations dialog.

Configure a run/debug configuration

  1. From the main menu, select .

  2. In the dialog that opens, create a new or open an existing run configuration.

  3. Click the Modify options link.

  4. In the Add Run Options list, under the Before Launch section, select Add before launch task. The list of tasks becomes available and the Build will be selected. Click the Close icon to disable it.

    Run/Debug Configuration dialog: Before launch
  5. If you need to add a new configuration action, click the Add button and from the list that opens, select the desired option.

    For example, if you select Build Project then IntelliJ IDEA will build the whole project before the run. In this case, the dependencies that for some reason were not included in the build with the Build action, will be accounted for. If you select the Build, no error check option, IntelliJ IDEA will run the application even if there are errors in the compilation results.

    Run/Debug Configuration: Add new configuration.

Review compilation and build output

IntelliJ IDEA reports compilation and building results in the Build tool window, which displays messages about errors and warnings as well as successful steps of compilation.

IntelliJ IDEA build output

If you configured an auto-build, then IntelliJ IDEA uses the Problems tool window for messages. The window is available even if the build was executed successfully. To open it, click Auto-build on the status bar.

Problems tool window

Double-click a message to jump to the problem in the source code. If you need to adjust the compiler settings, click the Compiler Properties icon.

Package an application into a JAR

When the code is compiled and ready, you can package your application in a Java archive (JAR) to share it with other developers. A built Java archive is called an artifact.

Create an artifact configuration for the JAR

  1. From the main menu, select File | Project Structure and click Artifacts.

  2. Click the Add button, point to JAR, and select From modules with dependencies.

  3. To the right of the Main Class field, click the Browse button and select the main class in the dialog that opens (for example, HelloWorld (com.example.helloworld)).

    IntelliJ IDEA creates the artifact configuration and shows its settings in the right-hand part of the Project Structure dialog.

  4. Apply the changes and close the dialog.

Creating an artifact configuration

Build the JAR artifact

  1. From the main menu, select Build | Build Artifacts.

  2. Point to the created .jar (HelloWorld:jar) and select Build.

    If you now look at the out/artifacts folder, you'll find your .jar file there.

The JAR artifact is built

Run a packaged JAR

To run a Java application packaged in a JAR, IntelliJ IDEA allows you to create a dedicated run configuration.

If you have a Gradle project, use Gradle to create and run the JAR file.

For Maven projects, you can use IntelliJ IDEA to run the JAR file. If you have a Spring Boot Maven project, refer to the Spring section.

Create a run configuration

  1. Press , find and run the Edit Configurations action.

  2. In the Run/Debug Configurations dialog, click the Add button and select JAR Application.

  3. Add a name for the new configuration.

    Creating a new run configuration
  4. In the Path to JAR field, click the Browse button and specify the path to the JAR file on your computer.

  5. Under Before launch, click the Add button, select in the dialog that opens.

    Doing this means that the JAR is built automatically every time you execute the run configuration.

    Specifying path to JAR file

Run configurations allow you to define how you want to run your application, with which arguments and options. You can have multiple run configurations for the same application, each with its own settings.

Execute the run configuration

  • On the toolbar, select the created configuration and click the Run button to the right of the run configuration selector. Alternatively, press if you prefer shortcuts.

    As before, the Run tool window opens and shows you the application output.

Running the packaged application

If the process has exited successfully, then the application is packaged correctly.

Last modified: 17 August 2021

Local HistoryMaven

Sours: https://www.jetbrains.com/help/idea/compiling-applications.html
IntelliJ IDEA: How to export executable JARs

A JAR (Java archive) file is a platform-independent package of your application in a single archive file. Packaging your application into a JAR makes it easier to distribute your program, and it also means functionalities in your program are reusable—for example, other programs can use your functionalities just by adding your JAR file as a dependency.

There are two types of JARs: normal and executable. Normal JARs have no entry point, meaning you cannot directly execute this type of JAR. You can only add it as a dependency to other programs and access the classes and functions in your program. On the other hand, an executable JAR can be executed directly without any external program. Simply put, you can start an executable JAR directly just by double-clicking on it.

IntelliJ provides a couple different ways to export a JAR from your workspace. In this tutorial, I’ll explain the two different methods for setting up your project architecture to export a JAR from IntelliJ:

  • Building an artifact in IntelliJ
  • Using Maven

To understand the tutorial better, you’ll use a simple example program that accepts user profile information as a command line argument. This program also uses Picocli and Apache Commons Cli as external dependencies, which will support validating and parsing the command line parameters.

Export a JAR Using the Build Artifact Method

In this method, you’ll export a JAR using the IntelliJ build option. Before starting up, you’ll need to create a project and add the necessary dependencies to it. Dependencies are external programs packaged as a JAR with some functionalities implemented already and can easily be reused in your program. You’ll also need to create a main class with some simple functionality.

Once you’ve created a project and a Run Configuration, which can be used to execute the project, let’s set up your program to export a JAR from the IntelliJ workspace.

1. Configure the project settings to define the artifacts of this project. Click Project Structure from the file menu.

Setting up the project structure

2. In the Project Structure window, click Artifacts in the left pane, then click the plus symbol. Expand the JAR option and click From module with dependencies.

Creating artifacts

This opens the Create JAR from Modules window.

Configuring JARs

3. Click the folder icon on the right side of the Main Class field to select the main class of your project. If you know the name of the main class, start typing in the field to see suggestions.

4. Set how external libraries should be handled while creating the JAR. There are two options:

    • Extract to the target JAR: This option extracts all the class files of your external libraries to the JAR you’re creating. This single JAR will contain your class files and also the class files from your external dependencies. This option is recommended because handling a single JAR is easier than handling multiple. You can easily add it to your other programs and execute it with a double click.
    • Copy to the output directory and link via Manifest: This option copies your dependency JARs to the output directory and creates a link with your Java program using the manifest file. If you select this option, you should also specify a location where the manifest file needs to be created. This method is recommended if you have a lot of JARs, and particularly if any of them are signed. Signed JARs may not work properly when you extract the class files into the JAR. Therefore, it’s better to copy the JARs to the output directory and use them via the manifest file.

5. Select the appropriate option and click OK, creating an artifact in your Artifacts window.

Configuring artifacts

You’ll see the name of the JAR in the Name field and its location in the Output directory. You can change the output directory to your desired location.

If you need a JAR to be created during each and every project build, select Include in project build. If you don’t need that, leave the option unselected. In that case, you can build the JAR when you’re done with your project development, using the Build Artifacts option.

Building artifacts

When you click Build Artifacts, the JAR is generated in the output directory you’ve selected.

So that’s how you export a JAR using the options available in IntelliJ. Next, you’ll see how to export a JAR using Maven.

Exporting a JAR Using Maven

Maven is a project management and automation tool, developed to make the build process easier. For example, you can create scripts to:

  • Build a project and create a JAR after each and every commit to your git repo.
  • Build a project nightly and deploy the JARs in the production systems when all the defined test cases are passing.
  • Automate build and deployment of projects with Jenkins.

To begin, create a Maven project in IntelliJ using this tutorial. Remember to add the necessary classes for your project. You can use the same class files and dependencies used in the previous section’s example.

When you create a new Maven project, you’ll have the minimal POM file created in your project directory with the following contents:

<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.draft.dev.maven.demo</groupId> <artifactId>com.draft.dev.maven.demo</artifactId> <version>1.0-SNAPSHOT</version> </project>

This POM file contains three important artifacts for the project:

  • : A unique base name of the company that creates and maintains the project.
  • : A unique name for the project itself
  • : Version number for the project

Configuring the Maven build

In this section, you’ll configure the aspects of your Maven build. You can add various plugins inside the build section of your POM file based on your requirements. Each will have different functions. These plugins will be executed during the build of your project.

In this tutorial, you’ll add the necessary plugin and configure it to export a JAR during the build.

1. Add the :

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>

This adds a Maven compiler for your projects and also denotes the for compiling your sources. Here, you’re using Java version 1.8.

2. Add the . This creates an assembly of your Java project.

<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <finalName>Command_Line_Program</finalName> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>com.askvikram.commandlinedemo.PicoCliSamplePgm</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>directory-single</goal> </goals> </execution> </executions> </plugin>

 

For a quick explanation of the plugin’s various sections:

  • : The name of the plugin itself
  • : Configures the maven assembly
  • : Final name of the assembly to be created
  • : Flag to include or exclude the assembly name in the JAR’s final name
  • : Adds instructions to the archive builder, in this case, adding the main class of your Java program in the manifest
  • : List of references to assembly descriptors available on the plugin’s classpath
  • : Tag to specify the activities to be performed during execution
  • : Here, is used to create a single file during the build

Now that you’ve configured the Maven settings for your project, the whole POM file for the project should look like this:

<?xml version="1.0" encoding="UTF-8"?> <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.askvikram</groupId> <artifactId>commandline.demo</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/info.picocli/picocli --> <dependency> <groupId>info.picocli</groupId> <artifactId>picocli</artifactId> <version>4.5.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <finalName>Command_Line_Program</finalName> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>com.askvikram.commandlinedemo.PicoCliSamplePgm</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>directory-single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>

Executing a Maven Build

Next, you’ll create a configuration for the Maven build and execute it. It’ll export a JAR in the directories you’ve specified.

1. Navigate to Run > Edit Configurations. The Run/Debug Configurations window opens.

Editing configurations

2. Select the Maven option from the Add New Configuration menu.

Adding new configuration

This will create a Maven run configuration for you as below.

Configuring new Maven configuration

3. Give the configuration a name and add the project’s home directory as your home directory.

4. In the command line field, add . These goals stipulate that the projects should be cleaned and the package should be installed in the appropriate directory.

5. Click Apply and OK. This creates a run configuration for you directly.

6. From the Run menu, click Run configuration_name.

Run configuration

You’ll see the build starting in your console, and after a few seconds, you’ll see the message . The JAR will be in the target directory of your Project home.

Remember, since this project has the configurations in a file, you can also configure an automatic build using Jenkins scripts on any trigger (for example, after every commit to your git repo).

Conclusion

Building a JAR in IntelliJ is a little complicated when it comes to configuring project structure and generating artifacts. In the case of using Maven, it’s even more difficult due to the setup involved with configuring the POM file and the project’s build processes.

But in this tutorial, you learned how to tackle two different options for building a JAR (using the build artifact method and using Maven) in IntelliJ to make the process easier. If you’ve got any suggestions or tips for creating a JAR that this article didn’t cover, please let me know about them in the comments.

Sours: https://lightrun.com/java/how-to-export-a-jar-from-intellij/

Jar intellij make

How to build jars from IntelliJ properly?

Here's how to build a jar with IntelliJ 10 http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/

-> -> -> -> Click -> ->

The above sets the "skeleton" to where the jar will be saved to. To actually build and save it do the following:

Extract to the target Jar

OK

Build | Build Artifact | Build

Try Extracting the .jar file from

ProjectName | out | artifacts | ProjectName_jar | ProjectName.jar


This is still an issue in 2017, I hope it will help somebody out there! I found 2 possibilities to create working jar-s under IntelliJ 2017.2

1. Creating artifact from IntelliJ:

File menu

Create a new artifact

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

enter image description here

You have to change manifest directory:

replace "java" with "resources"

This is how it should look like:

correct way for new manifest

  • Then you choose the dependencies what you want to be packed IN your jar, 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.

enter image description here

2. Using maven-assembly-plugin

Add build section to the pom file

  • Create a new run/debug configuration:

Create a new run/debug configuration:

Choose application

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

enter image description here

Final setup

enter image description here

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

JAR file location


I recently had this problem and think these steps are easy to follow if any prior solution or link is missing detail.

How to create a using IntelliJ IDEA 14.1.5:

  1. File > Save All.
  2. Run driver or class with main method.
  3. File > Project Structure.
  4. Select Tab "Artifacts".
  5. Click green plus button near top of window.
  6. Select JAR from Add drop down menu. Select "From modules with dependencies"
  7. Select main class.
  8. The radio button should be selecting "extract to the target JAR." Press OK.
  9. Check the box "Build on make"
  10. Press apply and OK.
  11. From the main menu, select the build dropdown.
  12. Select the option build artifacts.
Sours: https://newbedev.com/how-to-build-jars-from-intellij-properly
How to create a jar file with IntelliJ IDEA

How to build jars from IntelliJ properly?

This is still an issue in 2017, I hope it will help somebody out there! I found 2 possibilities to create working jar-s under IntelliJ 2017.2

1. Creating artifact from IntelliJ:

File menu

Create a new artifact

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

enter image description here

You have to change manifest directory:

replace "java" with "resources"

This is how it should look like:

correct way for new manifest

  • Then you choose the dependencies what you want to be packed IN your jar, 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.

enter image description here

2. Using maven-assembly-plugin

Add build section to the pom file

  • Create a new run/debug configuration:

Create a new run/debug configuration:

Choose application

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

enter image description here

Final setup

enter image description here

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

JAR file location

Sours: https://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly

You will also be interested:

Myself. And that's it. The river saved the case. After lunch, we went there.



5186 5187 5188 5189 5190