LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-24-2011, 12:08 AM   #1
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Rep: Reputation: 2
java error: Could not find the main class:


Hello,

I recently downloaded a java app (logbook manager with IR interface
for a "Galelo sol" diving computer) and when I attempted to run it,
I've got an error:

Code:
<localhost>.../JTrak_119_linux>java -jar jtrak_linux.jar
Exception in thread "main" java.lang.NoClassDefFoundError: de/frobese/jtrak/model/LogbuchManager
Caused by: java.lang.ClassNotFoundException: de.frobese.jtrak.model.LogbuchManager
	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: de.frobese.jtrak.app.JTrakLinux. Program will exit.
When I open the file "jtrak_linux.jar" with archive manager,
I can find in it a file

/de/frobese/jtrak/app/JTrakLinux.class

the path looks like what "java" attempted to search for
(at least, relative to the "jar" file). It's the first
time I attempt to lauch java app from a ".jar" archive
so it's possible I have some setup problem (I have
a"NightVision java app which starts OK but it's
started by a rather complex script and not by "-jar"
argument).

Do I have to "setenv" some env. variable?

TIA for any help,
kaza.
 
Old 04-24-2011, 04:32 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
I think the problem class is actually de.frobese.jtrak.model.LogbuchManager, do you have this class? It might be in another jar file, in which case you probably need to add that jar file to your CLASSPATH variable, or your command line:

java -cp path/to/lib/with/LogbuchManager -jar jtrak_linux.jar

There should be a script or batch file or something with this sort of information if it's needed to run the app... does it come with any files other than the main jtrak_linux jar?
 
Old 04-24-2011, 09:56 AM   #3
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Original Poster
Rep: Reputation: 2
Hi CroMagnon, thanks for the reply.

In the same directory where the main ".jar" file resides there is a "lib" directory with
few more ".jar" files, here's the output of "ls -lR":

Code:
.:
total 72
-rwxr-xr-x. 1 user user  1771 Jul 03 2009 11:56:26 jtrak_linux.jar
drwxr-xr-x. 2 user user  4096 Jul 12 2009 21:51:06 lib
-rwxr-xr-x. 1 user user 61466 Jul 03 2009 12:46:28 libirsock.so

./lib:
total 4784
-rwxr-xr-x. 1 user user   29770 Jul 03 2009 11:56:26 comm.jar
-rwxr-xr-x. 1 user user   81567 Jul 03 2009 11:56:26 FormatedTextFields-2.0.jar
-rwxr-xr-x. 1 user user  696567 Jul 03 2009 11:56:26 hsqldb.jar
-rwxr-xr-x. 1 user user   34260 Jul 03 2009 11:56:26 irsocket.jar
-rwxr-xr-x. 1 user user  150793 Jul 03 2009 11:56:26 jdom.jar
-rwxr-xr-x. 1 user user  500623 Jul 03 2009 11:56:26 jh.jar
-rwxr-xr-x. 1 user user   45720 Jul 03 2009 11:56:26 jir.jar
-rwxr-xr-x. 1 user user 1152645 Jul 03 2009 11:56:26 jtrak_help.jar
-rwxr-xr-x. 1 user user  412718 Jul 03 2009 11:56:26 JTrak.jar
-rwxr-xr-x. 1 user user  222725 Jul 03 2009 11:56:26 jtrak_resources.jar
-rwxr-xr-x. 1 user user  324303 Jul 03 2009 11:56:26 local_extensions.jar
-rwxr-xr-x. 1 user user  352668 Jul 03 2009 11:56:26 log4j-1.2.8.jar
-rwxr-xr-x. 1 user user   59347 Jul 03 2009 11:56:26 MRJAdapter.jar
-rwxr-xr-x. 1 user user  802216 Jul 03 2009 11:56:26 poi-2.5.1-final-20040804.jar
Inside the file "JTrak.jar" there is (among many others) the file:

/de/frobese/jtrak/model/LogbuchManager

so it seems I have to explain to java to look there.
Looking at the contents of the file

/META-INF/MANIFEST.MF

I see:

Code:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.4.2-90 (Apple Inc.)
Main-Class: de.frobese.jtrak.app.JTrakLinux
Class-Path: lib/jtrak_resources.jar lib/jtrak.jar lib/log4j-1.2.8.jar 
 lib/FormatedTextFields-2.0.jar lib/comm.jar lib/hsqldb.jar lib/irsock
 et.jar lib/jh.jar lib/jir.jar lib/jtrak_help.jar
BTW, the Class-Path is not a single line wrapped to 3 lines but 3 distinct lines
separated by "new line" and even breaking the "lib/irsock" and what looks like its remaining
"et.jar"

Should I get all of the text after "Class-Path to be a single line?

I attempted adding a class path with the "-cp" but got the same error:

Code:
<localhost>.../JTrak_119_linux>java -cp lib jtrak_linux.jar
Exception in thread "main" java.lang.NoClassDefFoundError: jtrak_linux/jar
Caused by: java.lang.ClassNotFoundException: jtrak_linux.jar
	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: jtrak_linux.jar. Program will exit.
What am I missing?

TIA for any ideas,
kaza.



Quote:
Originally Posted by CroMagnon View Post
I think the problem class is actually de.frobese.jtrak.model.LogbuchManager, do you have this class? It might be in another jar file, in which case you probably need to add that jar file to your CLASSPATH variable, or your command line:

java -cp path/to/lib/with/LogbuchManager -jar jtrak_linux.jar

There should be a script or batch file or something with this sort of information if it's needed to run the app... does it come with any files other than the main jtrak_linux jar?
 
Old 04-24-2011, 05:41 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Try it like this:

Code:
java -cp lib/jtrak_linux.jar -jar jtrak_linux.jar
I'm not overly familiar with java apps, but from my java(1) man page it sounds like the manifest overrides the command line classpath anyway, so this may make no difference (I'm on a Mac, so it's possible your implementation is different). The format of the manifest is ok according to the manifest spec, though I would probably try to keep individual items whole, instead of splitting them. As long as a line starts with a space, it is a continuation line.

Another option is just extracting the jar file and running the main class yourself, setting CLASSPATH to include everything:
Code:
export CLASSPATH=$CLASSPATH:lib/*
java de.frobese.jtrak.app.JTrakLinux
 
Old 04-25-2011, 07:11 AM   #5
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
Try the following code

Code:
APP_FOLDER=FULL_PATH_OF_JTRACK_FOLDER_LOCATION

MAINCLASS="de.frobese.jtrak.app.JTrakLinux"
JTRAK_CLASSPATH=.

for file in `ls $APP_FOLDER/lib/*.jar`; do JTRAK_CLASSPATH=$JTRAK_CLASSPATH:$file; done

java -Djava.library.path=$APP_FOLDER -cp $JTRAK_CLASSPATH $MAINCLASS
 
Old 06-23-2011, 12:48 PM   #6
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Original Poster
Rep: Reputation: 2
Sorry for so long a gap, other pressing things to do.

I had a little "progress": when I used the command:

java -cp lib/* -jar jtrak_linux.jar

and the error message changed, meaning giving the list of all *.jar files in the "lib"
directory caused java to find the previously not found class:

Code:
<localhost>.../JTrak_119_linux>java -cp lib/* -jar jtrak_linux.jar
Exception in thread "main" java.lang.NoClassDefFoundError: lib/FormatedTextFields-2/0/jar
Caused by: java.lang.ClassNotFoundException: lib.FormatedTextFields-2.0.jar
	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: lib/FormatedTextFields-2.0.jar. Program will exit.
Please pay attention that the class path Java attempted to search for was: "lib/FormatedTextFields-2/0/jar"
while the file existing in the "lib" directory is named: "FormatedTextFields-2.0.jar".
It looks like Java mis-interpreted the dots in the file name as a class hierarchy delimiter
and replaced them with "/" characters. I attempted renaming the file to "FormatedTextFields-2_0.jar"
but it didn't allowed Java to find it, maybe because in the "manifest" file
the list of files in the "lib" directory contains the original name.

So, is there a way to alter Java's interpretation of the dots in filename of *.jar archives?

TIA for any help,
kaza.

Quote:
Originally Posted by mrcheeks View Post
Try the following code

Code:
APP_FOLDER=FULL_PATH_OF_JTRACK_FOLDER_LOCATION

MAINCLASS="de.frobese.jtrak.app.JTrakLinux"
JTRAK_CLASSPATH=.

for file in `ls $APP_FOLDER/lib/*.jar`; do JTRAK_CLASSPATH=$JTRAK_CLASSPATH:$file; done

java -Djava.library.path=$APP_FOLDER -cp $JTRAK_CLASSPATH $MAINCLASS
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA: Popup menu in diffrent class then main Applet, how to repaint()? Valkyrie_of_valhalla Programming 2 10-24-2009 03:14 PM
java super() main class trscookie Programming 2 09-26-2007 05:34 PM
Error:Failed to load Main-Class manifest attribute from imgbpatch.jar xbc Ubuntu 0 02-18-2007 03:37 PM
java This.class error when running Fredstar Programming 2 02-12-2006 11:48 PM
JAVA : cannot find class JFrame? OmniXBro Programming 11 06-04-2004 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration