+
+/******************** getmainclassfromjar ************************
+
+gets the name of the main class form a jar's manifest file
+
+***************************************************************************/
+utf* getmainclassnamefromjar(mainstring){
+ jclass class;
+ jmethodID mid;
+ jobject obj;
+
+ class = env->FindClass(NULL, "java/util/jar/JarFile");
+ if (class == NULL) {
+ log_text("unable to find java.util.jar.JarFile");
+ throw_main_exception_exit();
+ }
+
+ mid = env->GetMethodID(NULL, class, "<init>","(Ljava/lang/String;)V");
+ if (mid == NULL) {
+ log_text("unable to find constructor in java.util.jar.JarFile");
+ cacao_exit(1);
+ }
+
+ /* open jarfile */
+ obj = env->NewObject(NULL,class,mid,(env->NewStringUTF(NULL,(char*)mainstring)));
+ if (env->ExceptionOccurred(NULL) != NULL) {
+ env->ExceptionDescribe(NULL);
+ cacao_exit(1);
+ }
+
+ mid = env->GetMethodID(NULL, class, "getManifest","()Ljava/util/jar/Manifest;");
+ if (mid == NULL) {
+ log_text("unable to find getMainfest method");
+ cacao_exit(1);
+ }
+
+ /* get manifest object */
+ obj = env->CallObjectMethod(NULL,obj,mid);
+ if (env->ExceptionOccurred(NULL) != NULL) {
+ env->ExceptionDescribe(NULL);
+ cacao_exit(1);
+ }
+
+ mid = env->GetMethodID(NULL, (jclass)((java_objectheader*) obj)->vftbl->class, "getMainAttributes","()Ljava/util/jar/Attributes;");
+ if (mid == NULL) {
+ log_text("unable to find getMainAttributes method");
+ cacao_exit(1);
+ }
+
+ /* get Main Attributes */
+ obj = env->CallObjectMethod(NULL,obj,mid);
+ if (env->ExceptionOccurred(NULL) != NULL) {
+ env->ExceptionDescribe(NULL);
+ cacao_exit(1);
+ }
+
+
+ mid = env->GetMethodID(NULL, (jclass)((java_objectheader*) obj)->vftbl->class, "getValue","(Ljava/lang/String;)Ljava/lang/String;");
+ if (mid == NULL) {
+ log_text("unable to find getValue method");
+ cacao_exit(1);
+ }
+
+ /* get property Main-Class */
+ obj = env->CallObjectMethod(NULL,obj,mid,env->NewStringUTF(NULL,"Main-Class"));
+ if (env->ExceptionOccurred(NULL) != NULL) {
+ env->ExceptionDescribe(NULL);
+ cacao_exit(1);
+ }
+
+ return javastring_toutf((java_lang_String*)obj,true);
+}
+
+