This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes To convert a console based Eclipse project to JAR ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "To convert a console based Eclipse project to JAR ?" Watch "To convert a console based Eclipse project to JAR ?" New topic
Author

To convert a console based Eclipse project to JAR ?

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
I have a simple console based java program that takes some user input, creates a file, fills it with text and also displays the text filled.
I want to make this into something like an exe. So, I made it into a JAR and tried to run it. But, this caused an error
message(please see attached image). Why does this error occur and how do is solve it ?
Please also tell me why does such a program not invoke the console automatically ?

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't see any attached image.

But don't try to fix that by attaching an image, just copy and paste the error message for us to read.

As for why your code doesn't use the console, that would be because you ran it using java.exe instead of javaw.exe (or vice versa -- I don't remember which has a console because I haven't ever written a console app in Java).
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Paul Clapham wrote:I don't see any attached image.

But don't try to fix that by attaching an image, just copy and paste the error message for us to read.

As for why your code doesn't use the console, that would be because you ran it using java.exe instead of javaw.exe (or vice versa -- I don't remember which has a console because I haven't ever written a console app in Java).


I put the image instead to save the typing. How do I make my code use Javaw instead and run like an exe file ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

justin smythhe wrote:I put the image instead to save the typing.

Translation: I'm not going to do any work to make my question easier to answer by the volunteers at this site.

Not a winning strategy.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Bear Bibeault wrote:
justin smythhe wrote:I put the image instead to save the typing.

Translation: I'm not going to do any work to make my question easier to answer by the volunteers at this site.

Not a winning strategy.


That's not what I meant.
Here is the message -
Failed to load Main-Class manifest attribute from C:\Temp\AnalysisOfCVSjar.jar

I don't know how typing the error would be better than posting the image.

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

justin smythhe wrote:I don't know how typing the error would be better than posting the image.


It's because reading a short piece of text takes a fraction of a second whereas the image alternative requires me to see a blurry blob, click on it, and wait several seconds for another application to open up and display it. That's if I assumed the image was safe (safe for work, not a malware carrier, and so on). Summary: text is easy, image is a nuisance.

Anyway the error message says you haven't built your jar correctly. It doesn't have a Main-Class attribute in the manifest (as the message says) and therefore it isn't an executable jar. So java.exe versus javaw.exe doesn't come into the picture.
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Paul Clapham wrote:
Anyway the error message says you haven't built your jar correctly. It doesn't have a Main-Class attribute in the manifest (as the message says) and therefore it isn't an executable jar. So java.exe versus javaw.exe doesn't come into the picture.


Thanks for the info. I am now trying to make it work. Putting a link below for everyone to refer to:
Setting an application's entry point



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Looks like you've got hold of the right tutorial. Carry on then, let us know how it goes.
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Paul Clapham wrote:Looks like you've got hold of the right tutorial. Carry on then, let us know how it goes.


What i learned from the above link:
If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:

Main-Class: classname

The value classname is the name of the class that is your application's entry point.

Recall that the entry point is a class having a method with signature public static void main(String[] args).


Then, I used the tutorial below and tried to make a manifest file for my eclipse project. But it failed.
When I run the jar, i get an error - Could not find the main class: com.doIT.TestJar
Add a manifest file to project in Eclipse - Tutorial

btw, i unzipped this jar to see the contents. It has a manifest folder with manifest file and also my eclipse settings and other folders.

How, do I get this thing to work ?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

justin smythhe wrote:When I run the jar, i get an error - Could not find the main class: com.doIT.TestJar
Add a manifest file to project in Eclipse - Tutorial

btw, i unzipped this jar to see the contents. It has a manifest folder with manifest file and also my eclipse settings and other folders.

How, do I get this thing to work ?


Doesn't the error message suggest anything to you?

It says it couldn't find your main class. So is that class in the jar? (Hint: the error message says it isn't.) There should be a folder named "com" at the root of the jar, and it should contain a folder named "doIT", which in turn should contain your TestJar.class.
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Paul Clapham wrote:
justin smythhe wrote:When I run the jar, i get an error - Could not find the main class: com.doIT.TestJar
Add a manifest file to project in Eclipse - Tutorial

btw, i unzipped this jar to see the contents. It has a manifest folder with manifest file and also my eclipse settings and other folders.

How, do I get this thing to work ?


Doesn't the error message suggest anything to you?

It says it couldn't find your main class. So is that class in the jar? (Hint: the error message says it isn't.) There should be a folder named "com" at the root of the jar, and it should contain a folder named "doIT", which in turn should contain your TestJar.class.


It seems that I have to create a folder with the class files. I tried using this link to get the job done.
However, in the final step of making my jar, i see an option to choose the class with main method. It shows me the src folder and not the classes folder to select my class from.
According to what I read, eclipse creates a bin folder to put your classes into. This has created new doubts:
1- Can't I give it another name instead of bin ?
2- I don't know why I can't see the bin folder inside eclipse. But, I can see it by manually looking into the project folder.

Please help me. I feel I am close to the end.



BalaMurali dhar
Ranch Hand

Joined: Apr 14, 2012
Posts: 60
where is your code? what type of error you are getting?
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
BalaMurali dhar wrote:where is your code? what type of error you are getting?


Please tell me why the code needs to be posted for this issue.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Let me move this thread to the IDEs forum, since it seems to be entirely about how to do something in Eclipse.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

justin smythhe wrote:Please tell me why the code needs to be posted for this issue.

Because without seeing your project's structure, the code in question, and the full and complete error message, all we are doing is guessing. Which is fine if all you want is general suggestions on things to look at. But if you want a definitive solution for the problem you have run the more concrete information you can supply, the better.

You could provide the following:
1) A screen shot of the Eclipse project, with the Project Explorer view fully expanded so that all of your source files show up. (It is best to click the screen shot so that only the Project View show, don't send a full monitor shot)
2) The source code for the main class (the class with the main method, copy and pats this as text)
3) The full error message that you are seeing. I assume the error is in the Console view - copy and past the text into the post.

JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To convert a console based Eclipse project to JAR ?
 
Similar Threads
Can't connect to MySQL database with Hibernate
JAR execution problems
Setting up Classpath
SEAppInstall.bat not found in WebSphere4.0 AE
Reading a file and storing its contents into a String Array