Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30992 > unrolled thread
| Started by | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| First post | 2015-02-01 23:49 +0100 |
| Last post | 2015-02-02 06:53 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
catch unsupported class version error Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-02-01 23:49 +0100
Re: catch unsupported class version error Arne Vajhøj <arne@vajhoej.dk> - 2015-02-01 18:00 -0500
Re: catch unsupported class version error v_borchert@despammed.com (Volker Borchert) - 2015-02-02 00:29 +0000
Re: catch unsupported class version error Arne Vajhøj <arne@vajhoej.dk> - 2015-02-01 21:26 -0500
Re: catch unsupported class version error Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-02-02 06:53 +0000
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2015-02-01 23:49 +0100 |
| Subject | catch unsupported class version error |
| Message-ID | <mamaha$28kl$1@ariadne.rz.tu-clausthal.de> |
[Multipart message — attachments visible in raw view] — view raw
Hello, I use a Maven build to create a Jar file from my program. I'm using the Maven options <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> because within the source I use some 1.8 features e.g. thread-stealing pool. If I run the Jar on a version < 1.8 I get the error "unsupported major.minor version" with a stacktrace. IMHO I cannot catch the error, because it is thrown by a native method of the VM, I have found a solution, that I can compile a class with e.h. 1.7 option and check the running version of the VM and create an error message on a wrong version. I would like to create error like "You are need Java 1.8" and the user, which run's the Jar does not see the stacktrace. How can I do check the VM version and create a nice error message? Thanks phil
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-02-01 18:00 -0500 |
| Message-ID | <54ceb004$0$283$14726298@news.sunsite.dk> |
| In reply to | #30992 |
On 2/1/2015 5:49 PM, Philipp Kraus wrote:
> because within the source I use some 1.8 features e.g. thread-stealing pool.
>
> If I run the Jar on a version < 1.8 I get the error "unsupported
> major.minor version" with a stacktrace.
>
> IMHO I cannot catch the error, because it is thrown by a native method
> of the VM, I have found a solution,
>
> that I can compile a class with e.h. 1.7 option and check the running
> version of the VM and create an error
>
> message on a wrong version.
>
> I would like to create error like "You are need Java 1.8" and the user,
> which run's the Jar does not see the stacktrace.
>
> How can I do check the VM version and create a nice error message?
Maybe:
System.getProperty("java.version")
Arne
[toc] | [prev] | [next] | [standalone]
| From | v_borchert@despammed.com (Volker Borchert) |
|---|---|
| Date | 2015-02-02 00:29 +0000 |
| Message-ID | <mamgdm$ha6$3@Gaia.teknon.de> |
| In reply to | #30993 |
Arne Vajh??j wrote:
> On 2/1/2015 5:49 PM, Philipp Kraus wrote:
> > because within the source I use some 1.8 features e.g. thread-stealing pool.
> >
> > If I run the Jar on a version < 1.8 I get the error "unsupported
> > major.minor version" with a stacktrace.
> >
> > IMHO I cannot catch the error, because it is thrown by a native method
> > of the VM, I have found a solution,
> >
> > that I can compile a class with e.h. 1.7 option and check the running
> > version of the VM and create an error
> >
> > message on a wrong version.
> >
> > I would like to create error like "You are need Java 1.8" and the user,
> > which run's the Jar does not see the stacktrace.
> >
> > How can I do check the VM version and create a nice error message?
>
> Maybe:
> System.getProperty("java.version")
What about
try {
Class.forName("some.class.compiled.with.1_8")
} catch (UnsupportedClassVersionError e) {
...
} catch (ReflectiveOperationException e) {
...
}
--
"I'm a doctor, not a mechanic." Dr Leonard McCoy <mccoy@ncc1701.starfleet.fed>
"I'm a mechanic, not a doctor." Volker Borchert <v_borchert@despammed.com>
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-02-01 21:26 -0500 |
| Message-ID | <54cee04e$0$283$14726298@news.sunsite.dk> |
| In reply to | #30995 |
On 2/1/2015 7:29 PM, Volker Borchert wrote:
> Arne Vajh??j wrote:
>> On 2/1/2015 5:49 PM, Philipp Kraus wrote:
>>> because within the source I use some 1.8 features e.g. thread-stealing pool.
>>>
>>> If I run the Jar on a version < 1.8 I get the error "unsupported
>>> major.minor version" with a stacktrace.
>>>
>>> IMHO I cannot catch the error, because it is thrown by a native method
>>> of the VM, I have found a solution,
>>>
>>> that I can compile a class with e.h. 1.7 option and check the running
>>> version of the VM and create an error
>>>
>>> message on a wrong version.
>>>
>>> I would like to create error like "You are need Java 1.8" and the user,
>>> which run's the Jar does not see the stacktrace.
>>>
>>> How can I do check the VM version and create a nice error message?
>>
>> Maybe:
>> System.getProperty("java.version")
>
> What about
>
> try {
> Class.forName("some.class.compiled.with.1_8")
> } catch (UnsupportedClassVersionError e) {
> ...
> } catch (ReflectiveOperationException e) {
> ...
> }
That should also work.
But I would prefer an if statement over try catch to check
the version.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-02-02 06:53 +0000 |
| Message-ID | <slrnmcu7ot.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #30992 |
Philipp Kraus <philipp.kraus@flashpixx.de> wrote: > I use a Maven build to create a Jar file from my program. I'm using the > Maven options ><maven.compiler.source>1.8</maven.compiler.source> ><maven.compiler.target>1.8</maven.compiler.target> > because within the source I use some 1.8 features e.g. thread-stealing pool. I got curious about "thread-steling pool" and googled it. First hit was class ForkJoinPool, and the link pointed to the javadoc of 7. You might use other 1.8-features, but the example you gave seems not to be one of them. > I would like to create error like "You are need Java 1.8" I'm not a grammer-nazi about postings, but if the context is some wording to be used elsewhere then I am ;-) That said, leave the "are" out of the message: "You need ..." For the actual question there were already answers, but to add to them: at least the starting class (the one with the static main method) *needs* to be compiled with source&target 1.7 or even lower. If the running JVM cannot load your main class, then any version checking within it is obviously moot.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web