0

when i tried to compile a simple java program with a package name it shows me NoClassDefFoundError when I remove this, my program executes good.I don't want to use an IDE, so how to solve this

package com.example.satya;

public class Overloading{

int telugu,english,hindi,maths,science,social,languages,non_languages;

public int total(int sub1, int sub2, int sub3){
  int total = sub1+sub2+sub3;
  return total;
  }

public int total(int languages, int non_languages){
  int total = languages+non_languages;
  return total;
}

public static void main(String[] args) {

Overloading testOverloading = new Overloading();

int languages =  testOverloading.total(25,30,35);
int non_languages =   testOverloading.total(45,50,28);
testOverloading.total(languages,non_languages);

System.out.println(languages+non_languages);

}

}

  • 2
    Possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – StackFlowed Dec 23 '15 at 18:43
  • 1
    have you put you java file in folders corresponding to the package name – Ramanlfc Dec 23 '15 at 18:44
  • @Ramanifc I did put them already.compiles good but doesn't execute –  Dec 23 '15 at 18:48

1 Answers1

0

I test your code by making executable jar file.
I did not use IDE. I use "Atom" text editor.

First, you need to create folder structure.

root/bin = where jar file will be stored.
root/classes = where class file stored.
root/src/com/example/satya = where your source code stored.

create manifest file
root/classes/manifest.txt

Manifest-Version: 1.0  
Sealed: true
Main-Class: com.example.satya.Overloading
Class-Path: .

In terminal:

root# 

    javac -classpath classes:. -d classes src/com/example/satya/Overloading.java  

root/classes# 

    jar -cvmf manifest.txt ../bin/Overloading.jar com/example/satya 


root/bin# 

    java -jar Overloading.jar
Frakcool
  • 10,915
  • 9
  • 50
  • 89
ibocon
  • 1,352
  • 3
  • 17
  • 40