Solved

Jar File Error: Could not find main class.

Posted on 2006-06-09
10
230 Views
Last Modified: 2013-11-23
I build my jar file using BENV.
It doesn't work in a directory with "src" in it.  I.E. C:views\ifd\src\copper
All other times it works.  
0
Comment
Question by:tjwallace05
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
how do you run it ? by double clicking ? or java -jar yourjar.jar ?
did you specified its main class in MANIFEST.MF
  Manifest-Version: 1.2
  Main-Class: DiveLog
and how do you create jar ? jar -cmf yourjar.jar MANIFEST.MF *.class
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
typo --> jar -cmf should be jar -cfm
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
0
 

Author Comment

by:tjwallace05
Comment Utility
To make my jar, I use a program call BENV which is just a build enviroment.
I specified my main class in the Manifest file.
I run the jar file both by double clicking it and by running a batch file from the commandline.
It will not run (double clicking) in a directory with "src" in it but it will run anywhere else.
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
please post the content of the manifest along with the batch file

> It will not run (double clicking) in a directory with "src" in it but it will run anywhere else.
you mean the existance of another folder named "src" near the jar, does impact on the execution ?
could you explain more in which circumstance(s) it fails to run
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:tjwallace05
Comment Utility
this is the batch file I use to create the jar file.
@echo off
:: This script is used to launch the make.  Type mk /? for help
::

:: Test if the environment is set
IF "/%BENV_LATEST_ROOT%"=="/" GOTO error
IF "%OS%"=="Windows_NT" which java.exe 2>NUL 1>NUL
IF NOT "%OS%"=="Windows_NT" which java.exe >NUL
if ERRORLEVEL 1 goto notfound
IF "%OS%"=="Windows_NT" which javac.exe 2>NUL 1>NUL
IF NOT "%OS%"=="Windows_NT" which javac.exe >NUL
if ERRORLEVEL 1 goto notfound

:: Launch make
call findroot
sh %BENV_WORKAREA_ROOT%\build\gnu\bin\unix\Mk -T win32 %1 %2 %3 %4 %5 %6 %7 %8 %9
goto exit
:notfound
echo:
echo:You must first set JAVA Development environment by updating your PATH
echo:to include the JVM, the JAVA compiler, and SDK tools.
echo:
goto exit
:error
echo:
echo:You must first set the variable: BENV_LATEST_ROOT.
echo:
:exit


Batch file to run jar file:
@echo off
:: Batch file to set alias for executing the java application
::

:: Name of the jarfile
set jarname=jxcodegui.jar

:: Set alias
doskey jxcodegui=java -jar %jarname% $*

echo:Alias 'jxcode' has been set.  Run the command again to execute
echo:the application.
echo:
echo:To update the 'jxcode' alias. Run jxcode.bat again
echo:

Manifest file:
Manifest-Version: 1.0
Created-By: 1.4.2_11 (Sun Microsystems Inc.)
Main-Class: JXCodeGuiMain

My program generates skeleton files in the folder from which it is executed.  So if I run the program from a folder like C:\views\codegen\projects it will run but if I place the jar file in C:\views\codegen\src it will not run.  If "src" is found anywhere in the path name, it will not run.  Could not find main class is displayed.
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
> If "src" is found anywhere in the path name, it will not run
I cant understand what is the correlation of src in path with running of jar ?
I is more likely something that is thrown by the application not by the java runtime
what is the exact phrase of the error message ?
0
 

Author Comment

by:tjwallace05
Comment Utility
Java Virtual Machine Launcher

Could not find the main class.  Program will exit
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 500 total points
Comment Utility
this is definitively a classpath issue
can you run the code this way: java -cp jxcodegui.jar JXCodeGuiMain
you should first go to the directory where jxcodegui.jar is located otherwise the full path to jxcodegui.jar is needed
(I assumed JXCodeGuiMain is not in a package)
0
 

Author Comment

by:tjwallace05
Comment Utility
Thanks a lot.  That did it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
changePi Challenge 15 75
HashMap Vs TreeMap 12 47
Java asynchronous logging 4 31
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now