I have a laptop that can dual boot into Windows 7 or Ubuntu. Whenever I use Eclipse on Windows and then boot into Ubuntu or vice versa, Eclipse can't find some of the jar files I'm using for my project. Specifically, jfxrt.jar, for JavaFX.
For example, when I use Eclipse on Windows, under Referenced Libraries, it says that the jar file is in C:\Program Flies\Java\jdk1.7.0_25\jre\lib. When I boot into Ubuntu, it still says that the the jar is in C:\Program Flies\Java\jdk1.7.0_25\jre\lib, and surprise surprise, it can't find it. So I change it to the correct location for Ubuntu. It's all well and good until I boot back into Windows, where I have the same problem.
Is there any way to avoid this?
Did you add the jar to the library as an external jar? That would be the path it stores, then. Use a variable instead if you have to add it manually: http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.user/reference/preferences/java/buildpath/ref-preferences-classpath-variables.htm?cp=1_4_2_0_1_0 . It's possible, though, that if this is part of Java 7, you just need the latest version of Eclipse--it supports Java 7 explicitly.
Related
I'm setting up a Maven project based on Java/JavaFX 11 which should be both editable in IntelliJ and Visual Studio Code.
My JDK is 11.0.3 (Windows x64) from https://adoptopenjdk.net/.
The pom.xml has a dependency for
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
My app can be compiled and run with "compiler:compile" and "exec:java" in IntelliJ. So step one succeeded.
Now when opening the same project in Visual Studio compiling and running does not succeed with a lot of similar error message
The package javafx.scene.chart is accessible from more than one module: <unnamed>, javafx.controls
I added a settings.json file in .vscode to point to the correct JDK directory.
{
"java.dependency.packagePresentation": "hierarchical",
"java.home": "C:/Program Files/Java/jdk-11.0.3+7",
"java.configuration.updateBuildConfiguration": "automatic"
}
But it still seems VSC has issues with two JavaFX versions, or isn't using the correct JDK. In the "Java Dependencies" view I can see references from both "JRE System Library" and "Maven" to JavaFX. Is there a way I can exclude them from the JRE view?
Screenshots as how JavaFX references are shown in VSC:
Based on the last screenshot posted, it seems that you are using a JDK 11 that does include JavaFX.
While most of JDK distributions don't include JavaFX (OpenJDK, Oracle, AdoptOpenJDK among others), some vendors are bundling JavaFX with the JDK, like Liberica.
If you check Liberica's release notes for JDK 11.0.2:
Windows x86_64, Mac, Linux x86_64 and Linux ARMv7 distributions contain OpenJFX 11.0.2.
While this option simplifies the use of JavaFX (no need to add it to the module-path, as it is already part of it), it can be confusing if you use Maven or Gradle build tools and include the JavaFX dependencies, or if you have other JDKs installed without it.
So the fix is easy: either use JDK without JavaFX and provide it via Maven/Gradle dependencies, or use JDK with JavaFX and don't include them.
I guess the latter is the preferred option, in case you need to export/share your project, since others might not have the same setup. Also it makes it more flexible to new releases of JavaFX.
As an aside, note that you can produce your own JDK that bundles JavaFX, following the instructions at https://openjfx.io/openjfx-docs/#modular, section Custom JDK+JavaFX image.
I have created a Java application. And its ready for deployment.
I have made jar file from my code. wrapped it using launch4j and bundled jre with it and accessing my exe file(generated by launch4j).
So,No need to install JRE and Everything works fine.
But one small problem is that my Exe file has to be at some predefined relative path to the Bundled JRE.
For example let say user has installed it in E:/(My Soft) where My soft contains JRE files an my Exe file. Now if user copies the exe file to his desktop then he will not be able to execute it.
So, I want to is there any way i can bundle jre within my exe or any other tweek so that user can Execute the exe file from anywhere on his pc ?
Try use jnlp starter for your programms. Read more in official oracle documentation JNLP
There's one option to bundle JRE with exe is to create a Portable Edition app with for example jPortable. So you can execute exe anywhere on the PC without installing JRE. But the better option is to create a custom installer which will check current installation of JRE in the client PC and install it as an required option if no other compatible JRE found.
Is there a way to prevent that the Java installation routine (e.g. jdk-7u1-windows-i586.exe) copies java.exe into C:\Windows\system32 directory?
I have to install my software on a client's laptop and I don't want to break other Java applications which are already installed on the machine. In other words I want to install a private JRE which is only used by my software.
By now, I copied an already installed JRE from my computer to the client's machine.
I discovered yesterday that there is a problem with Java versions on Windows, as you know keeping java up to date these days is critical, especially the JRE used by Internet explorer located in the Windows system32 or syswow64 folder.
You can perform a search for java in your C: drive and look at the various executable files it finds to determine if the situation applies on a specific system.
After doing some research I find that when the Java updater runs, it only updates the files installed in the JAVA home , usually located on the program files, but it does NOT update the files located in the windows system folder. As a result and since the system folder is in the default system PATH , the usage of Internet Explorer continues to use an old version of the JAVA files ( java.exe , javaw.exe , javaws.exe )
The solution is to uninstall java using the control panel uninstall programs feature, download most recent version and install again.
Cheers!
Fernando
I recently upgraded to java 8 and discovered this problem as the java version under system32 was still java 7. It stops you even running version as it complains about the registry keys
U:\>java -version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
Doing the following pointed me to the culprit:
U:\>where java
C:\Windows\System32\java.exe
C:\Program Files\Java\jdk1.8.0_45\bin\java.exe
I 'solved' this problem by just deleting the java under system32! I'm unsure of what consequences this will have.
You can just provide the JRE you want to use on your software and:
Set the JAVA_HOME variable before you run your application
Point to the correct java.exe file (e.g. ..\jre1.5.0_22\bin\java <your_java_main>)
This can be done in a *.bat file for example.
After running the *.bat file you created, all other java version will be ignored and it won't matter which versions are, or will be, installed on that pc.
I found the newest JDK still doesn't write correct code against registry.
The issue is if a computer doesn't have JRE, JDK doesn't register JRE in registry correctly.
For those install JDK 1.7u72 Just add Software\JavaSoft\Java Runtime Environment as the error message indicate. And add a string entry of CurrentVersion with value 1.7.
And then add Software\JavaSoft\Java Runtime Environment\1.7 and put a JavaHome string entry with value "C:\Program Files\Java\jre7". And JRE will function correctly.
Blame Oracle, if you use Registry, then write correct code, otherwise don't use the Registry!
All you have to do is go to Control Panel -> Programs Uninstall a program. Uninstall the old java updates and keep the newest java update and java development kit update. Your newest java update and java development kit update should have the same number.
Windows 10 Solution
Check Java Version in Console (CMD) with java -version
Check in Console (CMD) with where java, which Java Path's are enlisted.
If it you shows you "C:\Windows\System32" in its output, you will have a problem to get to your %JAVA_HOME%, where your wanted Java version resides.
Meaning, you need to get rid of "java.exe" in "C:\Windows\System32".
Just uninstall the JRE in the Software ("Programs and Features")
Hint: Keep in mind, do NOT the JDK, here in my case "Java SE Development Kit 8 Update (64-bit)"), but the JRE.
One way I would try would be to create a write-only empty file with the name java.exe into the System32 folder.
i have to install JRE Programmability if the System does not have JRE, i had dected JRE is installed in the system or not, but i have no idea how to install JRE programmtically, some people said you can use installer, but i donot know how to use installer for this purpose i searched in sun documnet, installing JRE in slient mode, there's also i donot know how to use that command iie.fing.edu.uy/ense/asign/…
In order to run your Java program, you can do that without installing the JRE, that its, you can run the application in a computer without JRE, we do that every day.
The way is to deploy you application with an embedded JRE and use a script (.bar, .sh) to execute you application using the embedded JRE. So your application is self-contained and no requires external JRE. You need to copy the entire JRE folder into your application and start removing unused files using the test-error approach. You can also decrease the file sizes removing not needed classes, like in rt.jar (you can decompress, remove unused classes and zip again).
The problem with this approach is that you are violating the Oracle/SUN JRE distribution policy as you are distributing a JRE with fewer files. If the application is for internal use, I think it's OK, if you want to redistribute the application, you are in trouble.
Another question is how to install the JRE by code, you can try to ship the JRE with your application, using an installer detect if JRE is already installed and install it id needed. Doing that in Java code is not trivial, you can use Runtime to exec external programs...
Do not rely on JAVA_HOMEas is not actively used nowadays.
Example:
Say you application name is 'A', you folder structure can look like:
A
|-> Run.bat
|- jre
|- bin
|- lib
|- lib
|-> A.jar
You application main class is Main.java in package a. Your Run.batcan look like START "" jre\bin\javaw.exe -cp lib\A.jar a.Main
You only are calling the embedded jre in jre folder, by calling the bin\javaw.exe and passing the jar and main class. The jre folder can content and entire JRE as copied from c:\Program Files (x86)\Java\jre6\ (Windows 7).
If you can have a web based solution you can use deployjava
http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
I have already developed a setup.exe for windows, having features like autodetecting JRE version, autoinstalling required JRE version, autostart on windows start etc. I have made this exe from a jar file(jar file was not having the above mentioned features. Features are added later when transforming a JAR to EXE. Now I was wondering if I can somehow convert exe to DMG, APP or JAR or I can add the above mentioned features in my JAR file only.) By default Mac comes with Java version 5 and my application needs minimum Java version 6 to run
The normal way to distribute a Java application on a Mac is different than on Windows. You don't need a native binary to run a Java application on Mac because you can bundle it into an application (.app) file.
JarBundler, which is part of the Xcode Deveoper Tools, helps you insert your JAR file into a new .app file. You'll also specify your icon at this stage and the main class.
The app file is really just a folder. You can open the .app file as a folder by option-clicking on the application file and choosing "Show Package Contents" in the pop-up menu. Sometimes you may need to tweak the Info.plist file in the application, as there are a lot of options. There is complete documentation about the Info.plist file on the apple's developer website.
Once you have your application, you can bundle that up into a Package using PackageMaker, also part of the Xcode Developer Tools.
Further, you can bundle the package into a disk image (DMG) using DiskUtility, which you'll find in the Utilities folder.
Regarding Java versions, prior to Snow Leopard, Java 6 was only available for Intel Macs. If you require Java 6, you'll need to require that they have an Intel Mac with the latest updates or have Snow Leopard. Alternatively, you could package SoyLatte into your app to replace the native Java runtime. You'd basically be distributing a 32-bit version of Java 6 with your app.
Java 1.6 is not released for all macs. Mine for one does not have it there is nothing you do about it.
As for creating a dmg. In the mac os x install cd is a package called developer tools. Which includes an application called Jar Bundler that allows you to wrap jar's in to apple's .app files(exe's for mac). As for a dmg image you can create it from command line or from ant target.