Showing posts with label IntelliJ Idea. Show all posts
Showing posts with label IntelliJ Idea. Show all posts

Friday, July 1, 2022

How to add external jar or library on IntelliJ IDEA project

In this tutorial, we will learn how to add external jar files to the project and load it using Intellij Idea.

Load Jar for Simple Java Application:

Let's create a directory called libs under the project root directory and add all the external libraries. Now we need to load those Jar files using Intellij Idea.

In Intellij, click on >> File >> Project Structure or hit Ctrl + Alt + Shift + s. This will open the popup window to load library.

Note: Select the New project library as Java in step 2 as shown in the figure.

Then click ok to load the libs folder module and click on Apply and Ok. Now we can access the Jar from our java classes.

Loading Jar/Library from Gradle Project:

Add the following inside dependencies in build.gradle file.

dependencies {
//other dependencies
 
compile fileTree(dir: 'libs', include: '*.jar')
}

After that in IntelliJ idea you can see the Gradle on the right side, click on it and refresh the Gradle project as below:

Loading Jar/Library from Maven Project:

Add the following system dependency inside pom.xml file.

<dependency>
           <groupId>com.libName</groupId>
           <artifactId>lib-artifact</artifactId>
           <version>20220117</version>
           <scope>system</scope>
           <systemPath>${basedir}/libs/jar_file_name.jar</systemPath>
       </dependency>

Make sure to change the group id, artifact id, and system path.

After that from the IntelliJ idea on the right side, you can see the Maven click on it and refresh the project by clicking the project name as below.

Share:

Friday, January 7, 2022

How to set JVM arguments in IntelliJ Idea

In this tutorial, we will learn how we can set JVM argument in Intellij Idea. For e.g, if we need to set the JVM argument like -Djava.library.path=/path/to/native/library for native library.

For this, click on Add Configuration.   If you haven't created a configuration, then add one and assign the project working directory. Here we are adding 360learntocode as an example.

Now, if we don't see the VM options then click on Modify Option tab to add VM options.

After adding VM options, you can set the JVM arguments there and click apply and ok. If you want to add more than one argument use a comma to separate them.



Share:

Friday, June 5, 2020

IntelliJ Idea doesn't detect existing Java project.

What to do if your IntelliJ Idea doesn't detect your existing project. Sometimes it may be due to it doesn't find the JDK on you configure path. If you have such a problem reconfigure the JDK.
 
For this, go to: File >> Project Structures(Ctr + Alt + Shift + s) >> Project




Click New >> JDK and provide the path and select JDK. Sometimes it may be due to other versions of JDK setup, in that case, click and select the desired version of java from dropdown menu. Then click apply and ok. That may solve the issue with java not detecting.

Sometimes, although Java is detected we are not able to use the feature of Intellij idea like, run and debug classes, step in step out from class by ctr + click on method or class, find the usage of class and method by click on it. In this case, simply close the project and import it again. For this,

Go to: File >> Close Project >> Import Project




Select your desired project, and select "create from existing source", select the desired library and java version and finish the setup. This will resolve the issues 


Share: