I'm using Eclipse 3.7 on Ubuntu 12.04.
I have five .java files in a certain Eclipse project in the src folder. The project folder has (apart from the bin, lib and src folders), the help file and the properties file along with certain input files.
I need to create a .jar file with the java files, and make it executable from the command line, along with the properties file as a parameter.
For example :
java -jar <jar-file-name>.jar -info file.properties
I used Eclipse to export the project as a .jar file, into the bin folder.
I copied all the input files, the properties file and the help file into the dist folder and ran the command.
I got an error saying
Failed to load Main-Class manifest attribute from jar
I then checked this answer and did the needful (created the manifest file with a line) and the ran
jar cfm <jar-file-name>.jar <manifest-file-name> ./bin/*.class
It didn't work, and threw a ClassNotFoundException.
Any help would be appreciated.
EDIT
I added the Main class by choosing 'Next' instead of 'Finish' while exporting the .jar. Now, while executing it, it threw a "ClassNotFoundException" for the mysql connector jar. Even though, it is included in the lib folder which had been added while making the jar.
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Second EDIT
Relevant outputs.
java -cp ./lib/* -jar <non-runnable-jar>.jar -info info.properties
where ./lib/ has all the dependent jars.
It gave this error :
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at polygonprobability.Model.readTestingData(Model.java:178)
at polygonprobability.Model.<init>(Model.java:136)
at polygonprobability.Info.getModel(Main.java:290)
at polygonprobability.Main.loadInfo(Main.java:138)
at polygonprobability.Main.operInfo(Main.java:61)
at polygonprobability.Main.distribute(Main.java:170)
at polygonprobability.Main.parse(Main.java:81)
at polygonprobability.Main.main(Main.java:34)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at polygonprobability.DatabaseConnect.authorizeSQL(DatabaseConnect.java:50)
at polygonprobability.Model.readTestingData(Model.java:157)
... 7 more
For
java -cp /lib* -jar <non-runnable>.jar <packagename>.Main -info info.properties
It gave this error
Exception in thread "main" java.lang.NoClassDefFoundError: /lib64
Caused by: java.lang.ClassNotFoundException: .lib64
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: /lib64. Program will exit.