1

My website is hosted on Apache on ubuntu. I have been given a JAR file which has two folders inside it and some .class and .scc files. Lets say jar file name = myJarfile, folder inside this archive = myFolder, and Class inside this folder is = myClass.

I have been told to run the class like this:

java myFolder.myClass

but i get this error:

$ java myFolder.myClass 
Exception in thread "main" java.lang.NoClassDefFoundError: myFolder/myClass
Caused by: java.lang.ClassNotFoundException: esGateKeeper.cookieServer
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: myFolder/myClass.  Program will exit.

I also tried:

$ java myJarfile.myFolder.myClass
Exception in thread "main" java.lang.NoClassDefFoundError: myJarfile/myFolder/myClass
Caused by: java.lang.ClassNotFoundException: myJarfile.myFolder.myClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: myJarfile.myFolder.myClass.  Program will exit.

Admin told me it is CLASSPATH issue. I have no idea. My website uses PERL CGI and no JAVA at all. I am not JAVA programmer, and googling did not give me idea how to get this running.

the Class/or JAR file is supposed to start an IPC daemon on my localhost which i would communicate with from my PERL CGI, for authentication purposes. It decrypts the cookie I get from browser.

I am not sure what I will need to install on my server for this to run. I have java as below:

$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Client VM (build 17.0-b16, mixed mode, sharing)

Pl advice.

ty. Rajeev

_OK__ I resolved this by exporting a CLASSPATH variable pointing to the .jar file:

export CLASSPATH="/full/path/to/myJarfile.jar"

then executes fine:

$ java myFolder.myClass

starts the daemon....

But to be honest, I have no idea what is going on here. This .jar file has two folders in it: myFolder and a META-INF. myFolder has bunch of .class files and one .scc file. none of them is named "main"....

I appreciate the time and help extended to me.

ty. Rajeev

rajeev
  • 1,275
  • 7
  • 27
  • 45

1 Answers1

0

Experiment with adding the "-jar" flag to 'java'.

Assuming the "jar" file creates a stand-alone process, you can set the Java process to start on boot by adding the launch command to /etc/rc.local. If it's an important service, you'll also want to monitor it to make sure it's running, and be prepared to stop and start it manually. You might also consider automatically restarting if you detect that it's hung or not running.

As far as accessing it from Perl, you'll need to get documentation from the person who gave it to from that. I expect it would either run on a port or create a socket you can connect to. In either case, it shouldn't matter that it's a Java app. Perl's standard methods for connecting for ports or sockets would apply.

Regarding Classpath, I recommend you read some documentation for Classpath if you haven't already. If in doubt about the best variation, ask your JAR file provider to be certain.

Also see:

Community
  • 1
  • 1
Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • Tx. I read that thread. I am not sure about: Where is the classpath variable? how do i set it? what do i need to do in Apache (if I have to do anythign etall in apache config) to make this run everytime webserver starts? Accessing from PERL is actually not an issue. When I tried -jar switch I get below: `$ java -jar myJarfile.jar Failed to load Main-Class manifest attribute from myJarfile.jar` – rajeev Aug 07 '12 at 17:01