How can I test Java Applet application in the Firefox with different Java Plugins versions?
For instance, with Java 6 and Java 7?
Is there a way to guide Firefox to the correct java.plugin.dll?
Haven't found any Firefox command-line options with regard to NPAPI so far.
Finally, I managed to do this.
Steps to make your computer use another JRE/JDK:
Open regedit.
Open HKEY_LOCAL_MACHINE\SOFTWARE\MozillaPlugins\#java.com/JavaPlugin,version=XXX subtree.
Change Path value to the place, where your plugin dll is. E.g.: c:\java\jdk1.6.0_37\jre\bin\plugin2\npjp2.dll.
Change Version value E.g.: 1.6.0_37.
Make sure, that you have correct Java in %PATH% environment variable.
In the Control Panel -> Java -> View disable all javas that you will not use. Select only the one you need.
Have fun!
Deploy the applet using JNLP and specify the appropriate version in the j2se element of the resources section. That would be 1.6* & 1.7* respectively. Note that will only work for 1.6 versions that implement the Plug-In 2 architecture JRE (e.g. Oracle's 1.6.0_10+).
See also Java Web Start - Runtime Versioning for details on version string usage.
Alternately
Go to the control panel and navigate to the JNLP Runtime Settings.
To test in 1.6, select the 1.6 JREs, and deselect the 1.7.
Related
I am working on a project which runs on java 8, but I frequently use jasper reports which runs on java 7 for generating PDF reports. Problem is that I have to switch between the 7 & 8 versions for this. Is there any way I can let the system know which version of Java to use for which applications. My tomcat server is wrapped within a Hybris server instance which is run externally, so changing compliance level in Eclipse is of no help.
As per described here you can install any number of JDKs. The system default will be the one you added to the PATH variable under environment variables. When you create a new project in NetBeans select the desired JDK location. (Java 7 or Java8). You can refer this.
Maybe my question was misunderstood, but I found a way to acheive what I intended to do.
Set your JAVA_HOME to 1.7 version and open iReports application(it did not open if version is set to 1.8). Then reset JAVA_HOME back to 1.8 and run your application normally. Once iReports has started, there is no further issue while developing your reports.
It is more of a hack than a proper solution, but works well enough for me.
Can you define anywhere in your Java Project which JRE/JDK version should it pick up?
In eclipse when I choose the project >> right click >> Java Compiler and check the "Compiler compliance level" I see a certain version marked (1.7,1.6 etc). How is this chosen?
Or is this entirely just dependent on what JDK/JRE runtime version your server (tomcat) is using?
Thanks
Short answer:
No, you can not identify the version of java that will be "picked up" at runtime.
More of an Answer:
There are three Java versions that come into play when building and running something using Java.
The source version. This is the version of Java to which the source of the project complies. When compiling, you can pass a "source" (try google search for "set java source level") parameter to identify this version. In practice, I don't know the value of this.
The target version. This is the version of Java to which the compiled result will comply. As with "source version" you can pass this as a parameter to the compiler.
Runtime version. This is the version of java that is actually installed on the host that is running the compiled java (the byte codes). You can never configure this at compile time since this is the thing that is installed on the runtime host.
There are some caveats.
The source and target version numbers must be equal to or less than the version of the java compiler that is actually compiling the java source. For example, you can choose target version 1.7 if you are compiling using a version 1.8 java compiler. You may not choose target version 1.8 if you are compiling using version a 1.7 java compiler.
It is possible to install multiple versions of java on a host. It is not possible to choose which version of java tomcat will use to execute your application since the version of java that will be used by tomcat is the version of java that is running tomcat.
It is chosen in that drop down menu, you can set it to whatever you'd like. However, you must have that version installed on your system/server in order for the project to function correctly. If you go to Window->Preferences->Java->Installed JREs, you can see which JREs you have installed. When you create a new server element in eclipse, you can also set the JRE of the runtime, and just make sure it matches the version of your project.
How can I change the Projects Runtime Platform?
(standard NetBeans [8.1] Java Project [Java Application])
Details:
using Ubuntu with NetBeans 8.1
I have installed JDK 1.6, JDK 1.7 + JDK 1.8
My projects platform is Java 6.
My systems default Java is Java 7.
NetBeans-IDE was started with Java 8.
When I run the project via the IDE (Run project), the Project-Platform is used (which is Java 6).
I cannot change the Runtime Platform!
It's always: Project Platform
I tried to Manage Platforms..., but I still can't change the value of the Runtime Platform-ComboBox.
EDIT:
As I wrote in the comments, I don't want to change the Project-Platform.
The project should be compiled with Java 6 but run with Java 8 (when click on Run project).
What I want is:
Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
How can I change the Projects Runtime Platform?
Unfortunately you can't. As you point out, its value can only be Project Platform. Of course that invites the question "What is the point of even having that Runtime Platform field?".
I suspect that it may have been (unwisely) added to the GUI so that at some time in the future it will be possible to actually select a different JDK to run against. There is an open Bug Report for this: Bug 186747 - Can't Build and Run with Different Java Versions.
It's also worth noting that the Help documentation for the Run screen does not mention that Runtime Platform field. My own view is that the field should be removed until it serves a useful purpose.
What I want is: Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
Unfortunately that can't be done, as shown by the open bug. The best you can do right now is:
Create platforms for JDK 6 and JDK 8 in NetBeans.
Set the Java Platform to JDK 1.6 on the Libraries screen, and set the Source/Binary Format to JDK 6 on the Sources screen, then build to verify that no invalid APIs are being used.
Switch the Java Platform to 1.8 on the Libraries screen to run your 1.6 code under 1.8.
I realize that you don't want to do that, but unfortunately there's no silver bullet in the current release of NetBeans (8.2).
An alternative approach would be to build and run using only JDK 8, but include the Animal Sniffer Maven plugin "for checking projects against the signatures of an API", to verify that your 1.6 code was not using illegal APIs. But of course that's only viable for Maven projects.
Please look at Netbeans Project Setup - Setting the Target JDK in a Project
You just have to change the Runtime Platform at the Libraries option, that's all.
Just went through this pain for Apache NetBeans 14. I was trying to set a remote debug for a Raspberry Pi.
It works only if the jdk match on both the local and remote versions. In my case I set them both to 17.
I would have expected that the default jdk on the local machine should have been able to be changed but I fail to determine how.
I am running Ubuntu on the local machine so maybe the platform cannot be changed (don't know). Moving on.
Changed runtime platform
I am implementing an applet that gets some information from the user, including your name,
is system administrator, machine architecture and more the certificates and smartcards plugged list, all this is for checking the prerequisites of another applet.
In Windows all works perfectly, but I have problems getting smartcards info in MAC (OS X Lion Mountain), probably caused by this bug: Bug DB:- JDK-7195480 : javax.smartcardio does not detect cards on Mac OS X.
I found the following possible solutions (I think):
Use of another library without the bug as https://github.com/intarsys/smartcard-io
I looked at these discussions:
Force the JVM to run in 32bit (-d32) as described in the discussions at apple forums.
Force java applet to run in 32-bit instead of 64-bit JRE
Force VM to launch in 32-bit mode WebStart JNLP
For the first case I have the problem of lib be compiled to version 7, I need it to version 6,
I did not succeed to compile for 6, and the extra JARs are to big (+- 4MB).
For the second case, apparently this does not work on Windows (docs oracle javase 6 docs technotes guides javaws developersguide syntax)
And aparently have some limitations...
Does anyone know another lib (in Java 6) to get the smartcard information?
I need only reader name, card name and ATR.
Or someone would know a way to force the JVM from a Applet (simple method)?
Please, try to be clarified because I am beginner in Java!
..Or someone would know a way to force the JVM from a Applet (simple method)?
We cannot really 'force' the user to do anything (not that we should), but by launching the applet using Java Web Start we can request particular versions of the JRE. Here's a rundown.
Java Web Start - Runtime Versioning
Java Web Start can be used to ensure that an application
gains a certain minimum version of the JRE
(Java Runtime Environment) that it requires to run.
Web start can also be used to ensure a specific
micro-version of the JRE
is available to an application, or that an
earlier major release
is used (e.g. using 1.3, on a system where 1.6 is installed).
Unless the system is correctly configured, the user might be
prompted for download.
Minimum Version
Java web start can be used to ensure a Java project is launched
with a particular minimum version of Java. For example, if the application
uses generics, but nothing beyond what is available in Java 1.5, the
JNLP deployment descriptor might include a section that says..
..
<resources>
<j2se version='1.5+'>
...
</resources>
Micro Version
Besides being able to specify a minimum Java Major version, the
deployer can also mandate a particular micro-version. An example
of where this can be handy, might be seen in changes to JRE's based
on new information about Daylight Savings Time (which can be changed
by regional governments at any time they see the need to change them).
..
<resources>
<j2se version='1.5.0_11'>
...
</resources>
Earlier Version
Web start has a handy feature in that it can allow us to
test applications against specific earlier Java versions.
For example, if the local build environment is based around 1.6,
but an application is supposedly 1.5+, it pays to test the
final product in a 1.5 JRE prior to deployment. Invoking a 1.5
JRE in the 1.6 environment can be as simple as.
..
<resources>
<j2se version='1.5'>
...
</resources>
Note the difference to the first example, which used '1.5+',
whereas this one uses '1.5' - to indicate that only a 1.5
JRE will do.
An alternative version..
..
<resources>
<j2se version='1.5*'>
...
</resources>
Prompt for Download
A problem commonly reported by people deploying applications
via web start, is that they are being prompted to download versions
of Java that are already locally installed.
Even if a specific Java
version is installed, it might not be flagged as being 'available'
for use by web start.
This can be easily fixed.
Open the Java Control Panel.
Select the Java tab and click the View
button of Java Application Runtime Settings.
You might see something like this.
Note which ones are Enabled (right column). This PC is
set up to use
1.6.0,
1.5.0_11, or
1.5.0_08. Neither of the
1.5.0-beta or
1.5.0_01 micro versions is available.
That is purely by my choice - if I needed to test against these
very early 1.5 versions, I could simply enable them as needed.
Ensure any versions of interest are Enabled and the problem
should be fixed. Web start will be able to load that version of the
JRE and use it, without any prompt for download.
If you have versions installed that do not
appear in the User list, click Find to
launch the JRE Finder to
search for them. The (Java 1.6) JRE Finder will
present a dialog with a message along these lines.
In order to launch applications, Java Web Start needs to know
the locations of installed Java Runtime Environments.
You can either select a known JRE, or select a directory in
the file system from which to search for JREs.
A thread
on the web start forum also produced the following comments
from Andy Herrick.
On Windows, the list of available JRE's is populated from
the registry which contains pointers to all the publicly
installed JRE's.
(It will not automatically include private JRE's, such as
those installed by a JDK install, where "install public JRE"
is not selected.).
On unix it will only, by default, contain
the JRE it came with and any installed by java web start or
that came with any previous version of java web start that
had previously been run.
He adds a further note on specifying a download source..
Using either:
<j2se version="1.5*" href="http://java.sun.com/products/autodl/j2se">
or
<j2se version="1.5" >
will get you any 1.5 version available on the system.
If you use the href attribute, you are asking for the particular update release, so..
<j2se version="1.5" href="http://java.sun.com/products/autodl/j2se">
..will only work with 1.5.0_00.
As we know, we are in transition between Java 7 and Java 8. I have both Java 7 and Java 8 JDK installed. However in the interests of keeping a hands-off approach I want to make java 7 JDK my default Java build environment.
Leaving Java 8 JDK installed for trials, testing, and migration.
However at the current time, Netbeans 8 insists that Java 8 is-the default.
What I'd like to set: Java 7 is default.
And only specify Java 8 on a per-project basis until I'm satisfied with the new build. At that point, I imagine we would change our default Java. The challenge is that there's no clear way to change a default Java configuration.
This is not helped by the fact that the "Java Platform Manager"is not part of "Options", and lives on the Tools menu / "Java Platforms. I have been able to to this successfully with IDEAJ when moving from Java 6 to Java 7. Everyone is using Netbeans on this project so we need to achieve the same end with Netbeans. To be clear, I'm comfortable using Java 8 for the Netbeans runtime. It is just project builds that I want as a specific Java 7 target environment.
According to the topic below: In NetBeans how do I change the Default JDK?, changing NETBEANS_JDKHOME will also change my netbeans running environment. So I would prefer to just set the build-target generally. Thanks in advance!
see also:
In NetBeans how do I change the Default JDK?
Netbeans v8 README: "nbjdk.active [since 5.0u1] - name of a Java platform (JDK) to use when building and running".
If I understand you question properly, each project can be assigned it's own Java Platform property, for example, right click the project in question and select "Properties"...
From the properties dialog, select "Libraries" and then select the "Java Platform" you want to use...
Personally, I find having the platforms pre-configured simpler.
If you're upgrading a project, you may also need to check the "Source/Binary Format" property in the "Sources" sections (it's own the bottom), as it will stay at the level of the old version of Java (if you downgrade, it adjusts automatically)
One solution is to change the netbeans configuration file netbeans.conf with is located in ...\NetBeans 8.0\etc.
But it does not work well...
The bypass we found is to spefify the jdk in the shortcut that launch Netbeans into
"...\NetBeans 8.0\bin\netbeans.exe" --jdkhome "C:\Program Files (x86)\Java\jdk1.7.0_60"