[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.java.programmer

Could not find or load main class com.mindprod.ensure.Ensure

Could not find or load main class com.mindprod.ensure.Ensure

Roedy Green

6/13/2016 1:52:00 PM

I am getting this message when I try to run a very simple program
either via
java -jar ensure.jar
or
java com.mindprod.ensure.Ensure

Oddly I can run it without trouble inside the IntelliJ IDE.

The manifest looks fine and all the classes needed are in the jar.

have you ever seen this?

Further Jet cannot compile the jar complaining the main class is
missing.

THe main method looks like this

public static void main( final String[] args ) throws IOException

Roedy Green

6/13/2016 2:03:00 PM

On Mon, 13 Jun 2016 06:51:58 -0700, Roedy Green <inquiry@mindprod.com>
wrote:

> public static void main( final String[] args ) throws IOException

turn out "throws IOException" is the problem. I am pretty sure this
used to work. It stops Java from detecting the main method.

Eric Douglas

6/13/2016 2:16:00 PM

On Monday, June 13, 2016 at 10:02:38 AM UTC-4, Roedy Green wrote:
> turn out "throws IOException" is the problem. I am pretty sure this
> used to work. It stops Java from detecting the main method.

I've never had a problem declaring main to throw anything.

Ideally main shouldn't throw anything, you should want to try catch errors at that level.

Roedy Green

6/13/2016 2:35:00 PM

On Mon, 13 Jun 2016 06:51:58 -0700, Roedy Green <inquiry@mindprod.com>
wrote:

>
> public static void main( final String[] args ) throws IOException

something odd. I have dozens of other programs with a throws that
work fine.

Lew

6/13/2016 8:49:00 PM

On Monday, June 13, 2016 at 7:35:17 AM UTC-7, Roedy Green wrote:
> On Mon, 13 Jun 2016 06:51:58 -0700, Roedy Green <inquiry@mindprod.com>
> wrote:
>
> >
> > public static void main( final String[] args ) throws IOException
>
> something odd. I have dozens of other programs with a throws that
> work fine.

Throwing an exception from 'main' is an antipattern.

Roedy Green

6/13/2016 9:12:00 PM

On Mon, 13 Jun 2016 13:48:48 -0700 (PDT), Lew <lewbloch@gmail.com>
wrote:

>Throwing an exception from 'main' is an antipattern.
I usually only do this in one-shot programs.

Eric Sosman

6/14/2016 12:55:00 AM

On 6/13/2016 4:48 PM, Lew wrote:
>
> Throwing an exception from 'main' is an antipattern.

Citation?

--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

6/14/2016 1:57:00 AM

On 6/13/2016 8:54 PM, Eric Sosman wrote:
> On 6/13/2016 4:48 PM, Lew wrote:
>> Throwing an exception from 'main' is an antipattern.
>
> Citation?

I have never seen it catalogued as an anti-pattern.

And it is very common in various demos and adhoc programs.

But for a more serious program I would call it very bad for
a GUI program and a code smell warranting further investigation
of UX and exception handling for a console program.

Arne


Eric Douglas

6/14/2016 11:59:00 AM

On Tuesday, June 14, 2016 at 6:34:06 AM UTC-4, Martin Gregorie wrote:
> Your code summarises it pretty nicely. All I'd add is that the user needs
> to know what happened, so if the program uses GUI interface it should log
> the error[1] and report it to the user using a JOptionPane or similar. If
> its a command-line (headless) program it should log the error[1] and
> inform the user by writing one or more lines to System.err. In both cases
> it can simply terminate after its reported what happened.

We add an email to IT with a screenshot and full details of the error on all our crash logs.
It's mostly the end user you're worrying about crashing the programs, so aside from notifying IT, it should catch all errors to display a user friendly message, then restart or exit if necessary with as much cleanup as possible.

Eric Sosman

6/14/2016 3:31:00 PM

On 6/14/2016 7:59 AM, Eric Douglas wrote:
> On Tuesday, June 14, 2016 at 6:34:06 AM UTC-4, Martin Gregorie wrote:
>> Your code summarises it pretty nicely. All I'd add is that the user needs
>> to know what happened, so if the program uses GUI interface it should log
>> the error[1] and report it to the user using a JOptionPane or similar. If
>> its a command-line (headless) program it should log the error[1] and
>> inform the user by writing one or more lines to System.err. In both cases
>> it can simply terminate after its reported what happened.
>
> We add an email to IT with a screenshot and full details of the error on all our crash logs.

(I hope your users "opt in" to this surveillance. Screen shots may
reveal information the user might have preferred to keep private, as in
the case of Congressional candidate Mike Webb.)

But back to the original question: After you've logged or reported
or dissected or whatevered the error condition, what next? Swallow the
exception and System.exit(), or re-throw the exception from main()? For
myself, I'd find System.exit() noticeably *worse* than throwing, since
it makes your main() harder to call from places other than JVM startup.

--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Eric Douglas

6/14/2016 4:00:00 PM

On Tuesday, June 14, 2016 at 11:31:31 AM UTC-4, Eric Sosman wrote:
> (I hope your users "opt in" to this surveillance. Screen shots may
> reveal information the user might have preferred to keep private, as in
> the case of Congressional candidate Mike Webb.)

Of course. This is only in our application which only runs on our internal network. I expect there's not much in this company that needs to be kept secret from IT. The only ones who could possibly have such secrets are HR who doesn't use the application and the company president who doesn't use it much.

> But back to the original question: After you've logged or reported
> or dissected or whatevered the error condition, what next? Swallow the
> exception and System.exit(), or re-throw the exception from main()? For
> myself, I'd find System.exit() noticeably *worse* than throwing, since
> it makes your main() harder to call from places other than JVM startup.

Normally we don't crash at the top level, so our application normally allows us to fix a problem and let the user continue. I expect you should call System.exit() for anything severe enough to throw up to the top level. At least this is how you're supposed to get the return code if your main class is called from a command prompt. Otherwise I'm not sure what the difference is between an exit() and throwing an exception from the main().

Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Could not find or load main class com.mindprod.ensure.Ensure

Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te

Il servizio è completamente GRATUITO!