Intellij Java: java.lang.NoClassDefFoundError: org/json/JSONException












4















I need help. I spent several hours trying to solve this problem but I can't. I code on Intellij Community Edition 2018.2 OS Windows 10, here is my java project structure.



enter image description here



my Main.java source:



package id.simko;

public class Main {

public static void main(String args) {
System.out.println("Hello World!");

SqlServerConn sqlServerConn = new SqlServerConn();
sqlServerConn.connectDbSqlServer();
sqlServerConn.selectSqlServer();
}
}


SqlServerConn.java:



package id.simko;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.*;

class SqlServerConn {
private Connection conn;

void connectDbSqlServer() {

String db_connect_string = "jdbc:sqlserver://localhost";
String db_name = "db1";
String db_userid = "sa";
String db_password = "sa";

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_connect_string+";databaseName="+db_name,
db_userid, db_password);
System.out.println("connected to sql server");
} catch (Exception e) {
e.printStackTrace();
}
}

void selectSqlServer(){
Statement statement;
try {
// ... skipped for clarity
} catch (SQLException e) {
e.printStackTrace();
}
}
}


my MANIFEST.MF:



Manifest-Version: 1.0
Main-Class: id.simko.Main


My pom.xml:



<?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>id.simko</groupId>
<artifactId>replicator</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependencies>

</project>


I configured File -> Project Structure -> Artifacts, and added libs/java-json.jar.



enter image description here



Then lastly, on Intellij I clicked Build -> Build Artifacts -> replicator.jar -> Build. And my executable jar was created successfully.



But when I tried to run it, error happens. here is the screenshot.



enter image description here



please help.. I know this question already answered here: Java: NoClassDefFoundError: org/json/JSONException but the solution cannot solve my problem. maybe this is a bug from intellij?



====================================================================



LAST UPDATE FROM ME:
I tried for hours until I give up. For now, the only possible way to create an executable application out of java project in Windows 10 is by NOT using Intellij CE 2018.2. I tried NetBeans 8.2 IDE and I successfully created executable bat with gradle plugin & cygwin.



I will leave this question unanswered, because I know someday someone will have a way, but for now I give up and tried a different IDE, at least for creating executable.










share|improve this question




















  • 2





    External Jars you have used, have not been attached to the jar you created.

    – Nipuna Priyamal
    Jan 2 at 12:48











  • thank you for your help. How I can attach it?

    – Dika
    Jan 2 at 12:49






  • 1





    add external jars as dependency in your pom file

    – Nipuna Priyamal
    Jan 2 at 12:51






  • 1





    How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

    – Gaurav Agarwal
    Jan 2 at 12:58






  • 1





    @Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

    – 孙兴斌
    Jan 2 at 13:14


















4















I need help. I spent several hours trying to solve this problem but I can't. I code on Intellij Community Edition 2018.2 OS Windows 10, here is my java project structure.



enter image description here



my Main.java source:



package id.simko;

public class Main {

public static void main(String args) {
System.out.println("Hello World!");

SqlServerConn sqlServerConn = new SqlServerConn();
sqlServerConn.connectDbSqlServer();
sqlServerConn.selectSqlServer();
}
}


SqlServerConn.java:



package id.simko;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.*;

class SqlServerConn {
private Connection conn;

void connectDbSqlServer() {

String db_connect_string = "jdbc:sqlserver://localhost";
String db_name = "db1";
String db_userid = "sa";
String db_password = "sa";

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_connect_string+";databaseName="+db_name,
db_userid, db_password);
System.out.println("connected to sql server");
} catch (Exception e) {
e.printStackTrace();
}
}

void selectSqlServer(){
Statement statement;
try {
// ... skipped for clarity
} catch (SQLException e) {
e.printStackTrace();
}
}
}


my MANIFEST.MF:



Manifest-Version: 1.0
Main-Class: id.simko.Main


My pom.xml:



<?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>id.simko</groupId>
<artifactId>replicator</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependencies>

</project>


I configured File -> Project Structure -> Artifacts, and added libs/java-json.jar.



enter image description here



Then lastly, on Intellij I clicked Build -> Build Artifacts -> replicator.jar -> Build. And my executable jar was created successfully.



But when I tried to run it, error happens. here is the screenshot.



enter image description here



please help.. I know this question already answered here: Java: NoClassDefFoundError: org/json/JSONException but the solution cannot solve my problem. maybe this is a bug from intellij?



====================================================================



LAST UPDATE FROM ME:
I tried for hours until I give up. For now, the only possible way to create an executable application out of java project in Windows 10 is by NOT using Intellij CE 2018.2. I tried NetBeans 8.2 IDE and I successfully created executable bat with gradle plugin & cygwin.



I will leave this question unanswered, because I know someday someone will have a way, but for now I give up and tried a different IDE, at least for creating executable.










share|improve this question




















  • 2





    External Jars you have used, have not been attached to the jar you created.

    – Nipuna Priyamal
    Jan 2 at 12:48











  • thank you for your help. How I can attach it?

    – Dika
    Jan 2 at 12:49






  • 1





    add external jars as dependency in your pom file

    – Nipuna Priyamal
    Jan 2 at 12:51






  • 1





    How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

    – Gaurav Agarwal
    Jan 2 at 12:58






  • 1





    @Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

    – 孙兴斌
    Jan 2 at 13:14
















4












4








4








I need help. I spent several hours trying to solve this problem but I can't. I code on Intellij Community Edition 2018.2 OS Windows 10, here is my java project structure.



enter image description here



my Main.java source:



package id.simko;

public class Main {

public static void main(String args) {
System.out.println("Hello World!");

SqlServerConn sqlServerConn = new SqlServerConn();
sqlServerConn.connectDbSqlServer();
sqlServerConn.selectSqlServer();
}
}


SqlServerConn.java:



package id.simko;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.*;

class SqlServerConn {
private Connection conn;

void connectDbSqlServer() {

String db_connect_string = "jdbc:sqlserver://localhost";
String db_name = "db1";
String db_userid = "sa";
String db_password = "sa";

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_connect_string+";databaseName="+db_name,
db_userid, db_password);
System.out.println("connected to sql server");
} catch (Exception e) {
e.printStackTrace();
}
}

void selectSqlServer(){
Statement statement;
try {
// ... skipped for clarity
} catch (SQLException e) {
e.printStackTrace();
}
}
}


my MANIFEST.MF:



Manifest-Version: 1.0
Main-Class: id.simko.Main


My pom.xml:



<?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>id.simko</groupId>
<artifactId>replicator</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependencies>

</project>


I configured File -> Project Structure -> Artifacts, and added libs/java-json.jar.



enter image description here



Then lastly, on Intellij I clicked Build -> Build Artifacts -> replicator.jar -> Build. And my executable jar was created successfully.



But when I tried to run it, error happens. here is the screenshot.



enter image description here



please help.. I know this question already answered here: Java: NoClassDefFoundError: org/json/JSONException but the solution cannot solve my problem. maybe this is a bug from intellij?



====================================================================



LAST UPDATE FROM ME:
I tried for hours until I give up. For now, the only possible way to create an executable application out of java project in Windows 10 is by NOT using Intellij CE 2018.2. I tried NetBeans 8.2 IDE and I successfully created executable bat with gradle plugin & cygwin.



I will leave this question unanswered, because I know someday someone will have a way, but for now I give up and tried a different IDE, at least for creating executable.










share|improve this question
















I need help. I spent several hours trying to solve this problem but I can't. I code on Intellij Community Edition 2018.2 OS Windows 10, here is my java project structure.



enter image description here



my Main.java source:



package id.simko;

public class Main {

public static void main(String args) {
System.out.println("Hello World!");

SqlServerConn sqlServerConn = new SqlServerConn();
sqlServerConn.connectDbSqlServer();
sqlServerConn.selectSqlServer();
}
}


SqlServerConn.java:



package id.simko;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.*;

class SqlServerConn {
private Connection conn;

void connectDbSqlServer() {

String db_connect_string = "jdbc:sqlserver://localhost";
String db_name = "db1";
String db_userid = "sa";
String db_password = "sa";

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_connect_string+";databaseName="+db_name,
db_userid, db_password);
System.out.println("connected to sql server");
} catch (Exception e) {
e.printStackTrace();
}
}

void selectSqlServer(){
Statement statement;
try {
// ... skipped for clarity
} catch (SQLException e) {
e.printStackTrace();
}
}
}


my MANIFEST.MF:



Manifest-Version: 1.0
Main-Class: id.simko.Main


My pom.xml:



<?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>id.simko</groupId>
<artifactId>replicator</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependencies>

</project>


I configured File -> Project Structure -> Artifacts, and added libs/java-json.jar.



enter image description here



Then lastly, on Intellij I clicked Build -> Build Artifacts -> replicator.jar -> Build. And my executable jar was created successfully.



But when I tried to run it, error happens. here is the screenshot.



enter image description here



please help.. I know this question already answered here: Java: NoClassDefFoundError: org/json/JSONException but the solution cannot solve my problem. maybe this is a bug from intellij?



====================================================================



LAST UPDATE FROM ME:
I tried for hours until I give up. For now, the only possible way to create an executable application out of java project in Windows 10 is by NOT using Intellij CE 2018.2. I tried NetBeans 8.2 IDE and I successfully created executable bat with gradle plugin & cygwin.



I will leave this question unanswered, because I know someday someone will have a way, but for now I give up and tried a different IDE, at least for creating executable.







java intellij-idea noclassdeffounderror executable-jar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 3:17







Dika

















asked Jan 2 at 12:45









DikaDika

7001328




7001328








  • 2





    External Jars you have used, have not been attached to the jar you created.

    – Nipuna Priyamal
    Jan 2 at 12:48











  • thank you for your help. How I can attach it?

    – Dika
    Jan 2 at 12:49






  • 1





    add external jars as dependency in your pom file

    – Nipuna Priyamal
    Jan 2 at 12:51






  • 1





    How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

    – Gaurav Agarwal
    Jan 2 at 12:58






  • 1





    @Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

    – 孙兴斌
    Jan 2 at 13:14
















  • 2





    External Jars you have used, have not been attached to the jar you created.

    – Nipuna Priyamal
    Jan 2 at 12:48











  • thank you for your help. How I can attach it?

    – Dika
    Jan 2 at 12:49






  • 1





    add external jars as dependency in your pom file

    – Nipuna Priyamal
    Jan 2 at 12:51






  • 1





    How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

    – Gaurav Agarwal
    Jan 2 at 12:58






  • 1





    @Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

    – 孙兴斌
    Jan 2 at 13:14










2




2





External Jars you have used, have not been attached to the jar you created.

– Nipuna Priyamal
Jan 2 at 12:48





External Jars you have used, have not been attached to the jar you created.

– Nipuna Priyamal
Jan 2 at 12:48













thank you for your help. How I can attach it?

– Dika
Jan 2 at 12:49





thank you for your help. How I can attach it?

– Dika
Jan 2 at 12:49




1




1





add external jars as dependency in your pom file

– Nipuna Priyamal
Jan 2 at 12:51





add external jars as dependency in your pom file

– Nipuna Priyamal
Jan 2 at 12:51




1




1





How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

– Gaurav Agarwal
Jan 2 at 12:58





How are you creating the executable JAR? Are you using Maven to package the JAR? Is this dependency mentioned in pom.xml?

– Gaurav Agarwal
Jan 2 at 12:58




1




1





@Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

– 孙兴斌
Jan 2 at 13:14







@Dika Where did you get json-jar? You can unzip it and see if there exists org.json.JSONException

– 孙兴斌
Jan 2 at 13:14














2 Answers
2






active

oldest

votes


















0














Place the jar file under lib folder because while runtime it is not able to identify your jar I think so..






share|improve this answer































    0














    Open your replicator.jar (can use WinRAR) and see whether the class JSONException is available inside the jar. If not you need to include that inside your jar. For that you can use maven shade(https://maven.apache.org/plugins/maven-shade-plugin/) plugin or assemble plugin(http://maven.apache.org/plugins/maven-assembly-plugin/) to include all dependent classes into your executable jar.



    This post would help you
    Including dependencies in a jar with Maven






    share|improve this answer
























    • thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

      – Dika
      Jan 3 at 4:39













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006644%2fintellij-java-java-lang-noclassdeffounderror-org-json-jsonexception%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Place the jar file under lib folder because while runtime it is not able to identify your jar I think so..






    share|improve this answer




























      0














      Place the jar file under lib folder because while runtime it is not able to identify your jar I think so..






      share|improve this answer


























        0












        0








        0







        Place the jar file under lib folder because while runtime it is not able to identify your jar I think so..






        share|improve this answer













        Place the jar file under lib folder because while runtime it is not able to identify your jar I think so..







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 12:53









        SanthoshSanthosh

        11




        11

























            0














            Open your replicator.jar (can use WinRAR) and see whether the class JSONException is available inside the jar. If not you need to include that inside your jar. For that you can use maven shade(https://maven.apache.org/plugins/maven-shade-plugin/) plugin or assemble plugin(http://maven.apache.org/plugins/maven-assembly-plugin/) to include all dependent classes into your executable jar.



            This post would help you
            Including dependencies in a jar with Maven






            share|improve this answer
























            • thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

              – Dika
              Jan 3 at 4:39


















            0














            Open your replicator.jar (can use WinRAR) and see whether the class JSONException is available inside the jar. If not you need to include that inside your jar. For that you can use maven shade(https://maven.apache.org/plugins/maven-shade-plugin/) plugin or assemble plugin(http://maven.apache.org/plugins/maven-assembly-plugin/) to include all dependent classes into your executable jar.



            This post would help you
            Including dependencies in a jar with Maven






            share|improve this answer
























            • thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

              – Dika
              Jan 3 at 4:39
















            0












            0








            0







            Open your replicator.jar (can use WinRAR) and see whether the class JSONException is available inside the jar. If not you need to include that inside your jar. For that you can use maven shade(https://maven.apache.org/plugins/maven-shade-plugin/) plugin or assemble plugin(http://maven.apache.org/plugins/maven-assembly-plugin/) to include all dependent classes into your executable jar.



            This post would help you
            Including dependencies in a jar with Maven






            share|improve this answer













            Open your replicator.jar (can use WinRAR) and see whether the class JSONException is available inside the jar. If not you need to include that inside your jar. For that you can use maven shade(https://maven.apache.org/plugins/maven-shade-plugin/) plugin or assemble plugin(http://maven.apache.org/plugins/maven-assembly-plugin/) to include all dependent classes into your executable jar.



            This post would help you
            Including dependencies in a jar with Maven







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 14:18









            DushDush

            1,058613




            1,058613













            • thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

              – Dika
              Jan 3 at 4:39





















            • thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

              – Dika
              Jan 3 at 4:39



















            thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

            – Dika
            Jan 3 at 4:39







            thank you for the info. please see my updated question. fyi the dependency jars is included but somehow not loaded into the main application. maybe it can work using tools like one-jar, but for now I dont have time for experiment it

            – Dika
            Jan 3 at 4:39




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006644%2fintellij-java-java-lang-noclassdeffounderror-org-json-jsonexception%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory