Home » Newcomers » Newcomers » Create .jar file does not work
Create .jar file does not work [message #167165] |
Thu, 24 August 2006 19:08 |
Eclipse User |
|
|
|
Originally posted by: dgresh.lle.rochester.edu
Hi,
I'm trying to create a .jar file of a package. However, it is not working
for some reason. I right-click the package, and click export. Then, I
click JAR file and follow the instructions.
I tell it to export the package from my workspace. I tell it to export
generated class files and resources, as well as java source files and
resources. I tell it to compress the contents, and add directory entries.
I then specify the filename.
I hit next, and tell it to export class files with compile errors and
warnings.
I hit next, and select my main class from my package. I hit "browse" and
click on GUI, so it sets it to jena.GUI (jena is my package, GUI is my
class). I hit finish.
It creates the .jar file. When I double-click the .jar file, I get a
message saying "Could not find the main class. Program will exit."
What does this mean? What have I done wrong? I have specified my main
class, I have exported the necessary files...what is it complaining about?
It makes no difference if I check the boxes on the first page to export
classpath and .project; the same result happens.
Can someone please offer some advice? Is there something I am missing?
Thanks,
Dan
|
|
|
Re: Create .jar file does not work [message #167189 is a reply to message #167165] |
Thu, 24 August 2006 23:26 |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Dan Gresh" <dgresh@lle.rochester.edu> wrote in message
news:ef043d6bd81bd9e7cd75ebf86c9e1b44$1@www.eclipse.org...
> [...]
> It creates the .jar file. When I double-click the .jar file, I get a
> message saying "Could not find the main class. Program will exit."
>
> What does this mean? What have I done wrong? I have specified my main
> class, I have exported the necessary files...what is it complaining about?
> It makes no difference if I check the boxes on the first page to export
> classpath and .project; the same result happens.
>
> Can someone please offer some advice? Is there something I am missing?
If you view the contents of the .jar (e.g., with WinZip or the like), are
the contents what you expect?
|
|
| | |
Re: Create .jar file does not work [message #167417 is a reply to message #167371] |
Fri, 25 August 2006 13:59 |
Eclipse User |
|
|
|
Originally posted by: dgresh.lle.rochester.edu
Hi,
After searching google and stuff, it seems as if it could be a classpath
error. However, how could this happen? When I create the .jar file, I
export .classpath and .project, and those files are included in the .jar
when I view it with WinZip. I have set a bunch of external jars up to my
project folder's build path. Is there a different way I should be doing
this?
Thanks,
Dan
|
|
|
Re: Create .jar file does not work [message #167455 is a reply to message #167417] |
Fri, 25 August 2006 16:17 |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Dan Gresh" <dgresh@lle.rochester.edu> wrote in message
news:d588d775996f1b97423f46efa5ad49a6$1@www.eclipse.org...
> Hi,
>
> After searching google and stuff, it seems as if it could be a classpath
> error. However, how could this happen? When I create the .jar file, I
> export .classpath and .project, and those files are included in the .jar
> when I view it with WinZip. I have set a bunch of external jars up to my
> project folder's build path. Is there a different way I should be doing
> this?
The .classpath and .project files are input to an Eclipse project. That is,
they tell the compiler how to build the project, when building within
Eclipse. They don't have anything to do with how Eclipse *runs* a plug-in,
though. The runtime classpath is determined in the bundle manifest
(MANIFEST.MF). Take a look at the "Runtime" tab on the manifest editor.
Make sure that your runtime classpath contains '.' (without the quotes) as
well as any nested .jar files.
|
|
|
Re: Create .jar file does not work [message #167477 is a reply to message #167455] |
Fri, 25 August 2006 16:55 |
Eclipse User |
|
|
|
Originally posted by: dgresh.lle.rochester.edu
Well, the Manifest.mf file in the .jar does not specify any classpath.
That is probably not good.
I searched help, but I can't seem to find the Manifest Editor. Could you
kindly direct me to where it is?
|
|
|
Re: Create .jar file does not work [message #167500 is a reply to message #167477] |
Fri, 25 August 2006 18:51 |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Dan Gresh" <dgresh@lle.rochester.edu> wrote in message
news:d98e200b6bdc1c34f96cbc50a2e10530$1@www.eclipse.org...
> Well, the Manifest.mf file in the .jar does not specify any classpath.
> That is probably not good.
>
> I searched help, but I can't seem to find the Manifest Editor. Could you
> kindly direct me to where it is?
I'm sorry, I got confused and sent you down a bad path. When I wrote that
last post I was thinking you were working on a plug-in project, rather than
an ordinary Java project.
The comment about classpath still applies, though. It sounds like you've
successfully created a jar file that contains the classes you want; and I'm
assuming they are in the right place relative to the root of the jar, that
is, a class like org.example.Foo shows up in the jar file as
org/example/Foo.class.
But you're saying that when you double-click the jar file, you get a "Could
not find the main class. Program will exit."
Where are you doing this double-click?
Does your manifest.mf have a line like "Main-Class: x.Main"?
|
|
|
Re: Create .jar file does not work [message #167514 is a reply to message #167500] |
Fri, 25 August 2006 19:07 |
Eclipse User |
|
|
|
Originally posted by: dgresh.lle.rochester.edu
I double-click the JAR file in my directory. Also, I have tried running
the JAR from the command line using the java -jar myJar.jar command, and I
get the same error.
Yes, the file has a Main-Class header. There have been some changes:
If I launch GUI.class from the JAR file, it works fine. The GUI displays
and everything in GUI.class works fine. However, if I tell my GUI class to
load another class, DBQuery (which is what I really want it to do), that
makes use of external JAR files, I get the error I mentioned earlier.
The Manifest.mf file has a Main-Class header as I said earlier, but it
does NOT have a Class-Path header. I tried adding the Class-Path header,
and I got the 'Exception in thread "main"' error and all that.
|
|
|
Re: Create .jar file does not work [message #167520 is a reply to message #167514] |
Fri, 25 August 2006 21:07 |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Dan Gresh" <dgresh@lle.rochester.edu> wrote in message
news:4550f9e0cf58868dbed6c63f5b79d911$1@www.eclipse.org...
>I double-click the JAR file in my directory. Also, I have tried running the
>JAR from the command line using the java -jar myJar.jar command, and I get
>the same error.
>
> Yes, the file has a Main-Class header. There have been some changes:
>
> If I launch GUI.class from the JAR file, it works fine. The GUI displays
> and everything in GUI.class works fine. However, if I tell my GUI class to
> load another class, DBQuery (which is what I really want it to do), that
> makes use of external JAR files, I get the error I mentioned earlier.
> The Manifest.mf file has a Main-Class header as I said earlier, but it
> does NOT have a Class-Path header. I tried adding the Class-Path header,
> and I got the 'Exception in thread "main"' error and all that.
Is it possible that the manifest itself is in the wrong location? Should be
meta-inf/manifest.mf. Might need to be all caps, I can't remember. If you
auto-generated the manifest it should be correct.
Sorry, I don't have many ideas left.
|
|
|
Re: Create .jar file does not work [message #167528 is a reply to message #167417] |
Sat, 26 August 2006 01:27 |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
Dan Gresh wrote:
> Hi,
>
> After searching google and stuff, it seems as if it could be a classpath
> error. However, how could this happen? When I create the .jar file, I
> export .classpath and .project, and those files are included in the .jar
> when I view it with WinZip. I have set a bunch of external jars up to my
> project folder's build path. Is there a different way I should be doing
> this?
>
> Thanks,
> Dan
>
If you have dependencies on external jars to run your project, you need
to get them on the class path. They won't be included in the .jar file
that you create.
I'm not an expert on manifest files in .jar files, so I'm not sure
how/if you can specify external .jar files on in the manifest. If not,
you will need to add a -cp {list of jar files} to your command line or
define them in your CLASSPATH environment variable.
|
|
|
Re: Create .jar file does not work [message #167582 is a reply to message #167528] |
Sat, 26 August 2006 20:21 |
Paul A. Rubin Messages: 188 Registered: July 2009 |
Senior Member |
|
|
David Wegener wrote:
> Dan Gresh wrote:
>> Hi,
>>
>> After searching google and stuff, it seems as if it could be a
>> classpath error. However, how could this happen? When I create the
>> .jar file, I export .classpath and .project, and those files are
>> included in the .jar when I view it with WinZip. I have set a bunch of
>> external jars up to my project folder's build path. Is there a
>> different way I should be doing this?
>>
>> Thanks,
>> Dan
>>
> If you have dependencies on external jars to run your project, you need
> to get them on the class path. They won't be included in the .jar file
> that you create.
>
> I'm not an expert on manifest files in .jar files, so I'm not sure
> how/if you can specify external .jar files on in the manifest. If not,
> you will need to add a -cp {list of jar files} to your command line or
> define them in your CLASSPATH environment variable.
I'm not sure you can specify a classpath in the manifest, but I'm pretty
sure you wouldn't want to. If the code in the .jar file depends on any
classes not included in the .jar file, you're relying on the user having
installed them -- but you can't be sure *where* the user installed them.
So it's up to the user to get them on the system CLASSPATH or specify
them with -cp at run time. I think.
/Paul
|
|
| |
Goto Forum:
Current Time: Sat Dec 21 18:59:33 GMT 2024
Powered by FUDForum. Page generated in 0.08568 seconds
|