Unable to run executable jar file using double click - java

I was having jdk_1.6 in my machine and I removed it and installed jdk_1.7. So after installing jdk_1.7 I am not able to run my jar file with double click. I could run the same file using command prompt.
After installing jdk_1.7 I run the program from eclipse using java 7 and I exported jar using the same.
I am using following command for running jar:
>>java -jar csv_generator_1.jar
And this works fine and jar get executed.
But when I right click and open with javaw.exe in jad/bin folder or jdk/jre/bin/ folder it's not working.
I found same question here link1 and link2, but I am not understating what to do.
Can someone help me to resolve this?

Go there and download newest verson of java RE and install it and it should work. But if it does not work you should get some kind of error message and try to google it. It is possible that your java(s) are broken.

If you install JDK, you may think it contains JRE but it's private. At least that was stated during installation process. Therefore, you had to install Public JRE.
JDK installer provides an option to do so but if you didn't check it, you might experience the problem you described.

Related

I can't install Netbeans10

As a beginner for java,I found it's easy to install Netbeans8 but not Netbeans10.It seemed that I need to deal with the documents I downloaded.Here are the instuctions from the website of Netbeans but I don't understand why I can't install it.Please help me know how to deal with it.
To build Apache NetBeans (incubating) 10.0 from source you need:
Oracle’s Java 8 or Open JDK v8.
Apache Ant 1.10 or greater (https://ant.apache.org).
Once you have everything installed then:
Unzip incubating-netbeans-10.0-source.zip in a directory of your liking.
cd to that directory, and then run ant to build the Apache NetBeans IDE. Once built you can run the IDE by typing ./nbbuild/netbeans/bin/netbeans
Just download the bin folder from here and place it where you want your Netbeans installation to be.
Go to the bin folder and execute the IDE (NetBeans or netbeans64.exe which is depending on your system).
If you having trouble and NetBeans says it can't find your java SDK head to the etc folder and open the config file (netbeans.conf).
There you find a line that looks like this: #netbeans_jdkhome="/path/to/jdk"
Change that line to the path where your Java SDK is installed and DONT forget to remove the hashtag because then its referenced as a comment.
At the end it should like something like this: netbeans_jdkhome="C:/Programm Files/Java/jdk.x.x.x"
I Hope I could help you

AppleScriptEngine in java jar is not working, what am I missing?

I am trying to incorporate Apple's script engine in my java app developed for macOs. I use eclipse to develop and when I run a debug build from eclipse all the Apple Script functions work.
As soon as I export it to an external jar and run that on the same machine they do no longer work.
I've searched and found some issues which I all tried, here is a summary:
using getEngineByName("AppleScriptEngine") now.
Adding the META-INF file javax.script.ScriptEngineFactory with the contents: apple.applescript.AppleScriptEngineFactory
cleaning and rebuilding several times
I opened the jar to see if the META-INF file is present and it is.
searched in /System/Library/Java/Extensions/ for a applescript jar file but it was not there.
I also searched for the /Library/Java/JavaVirtualMachines to see if it is there but also not the case
It is still not working. So I do not know what the difference is exactly between eclipse debug run and running a jar in macOs but there has to be something I am missing.
As far as I can figure out it seems that the apple scripting class is not installed but then how does eclipse use it?
As I understand there is a difference between java JRE versions so I am in need of a solution for all of them because I do not know what systems are running my app.
Any help is appreciated!

Missing JRE in Eclipse in Mac OSX

I'm trying to run eclipse on my Mac OS X. I've been doing some Android programming on Eclipse lately, and today wanted to do some development on Java. However, to my surprise, Eclipse says there's no JRE/JDK installed. I don't know how this is possible, since my android projects have worked very well so far, and even now. I've tried the following items:
Checking java version through the Mac terminal. It says java version "1.8.0_20" is installed. Here's the screenshot.
I've checked the Java version through the Java Control Panel in System Preferences. Again, same thing:
I know that when there's no JRE visible in Eclipse, it can be manually entered through the "add" option under preferences > Java > Installed JREs in Eclipse. But although I can find the Contents folder in this path: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/home/contents, when I attempt to manually add this in Eclipse, the Java folder under users/library just doesn't show up. I have no idea why this is happening. Here are some screenshots, just in case:
As you can see, the Java folder just doesn't show up under Library in the above screenshot.
Lastly, I've also tried to hit "Search" in Eclipse (same place as "Add" in one of the screenshots above), but "Search" doesn't find anything at all.
I've gone through existing answers on SO which deal with similar problems. The only thing which I haven't done seems to be about setting a path variable, but they were all in Windows OS, so not sure if it applies in my situation.
I'd really appreciate any help on this.
Update 1: According to what has been pointed out so far, I tried copy-pasting the suggested path. But the error I get is: The home directory does not exist.
Here's the screenshot:
You are trying to find the JRE in a wrong Library directory as Library directory maybe present in more than one place. Just copy paste the jre path in 'jre home' input as
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/home/contents/Home/jre/
EDIT: To find where is your java installed on Mac, run the following command:
echo $(/usr/libexec/java_home)
it should return something like this:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
append jre to the end of this path to build JRE home path:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre

Runnable Jar made in Eclipse, Doesn't work on pc's without JDK installed

I've made a little snake game and exported it into a runnable JAR file through Eclipse.
It works perfect in machines with JDK installed (with regards to the environment variables and all that.)
But "normal" people don't have that installed, only the JRE that can be found here: http://java.com/en/download/index.jsp
This is insufficient to execute the JAR apparently. I've tried numerous approaches:
packeging libraries in Jar
Extracting libraries in Jar
Build with java 1.7
building with java 1.8
checked the build path to make sure the libraries is included.
At best I get a "Java Exception occured" on the other PC (the one with JDK installed).
I've then tried to run the JAR on my own machine through cmd with the command...
java -jar fileName.jar
...in the hope that I would get an error log, but nope, it just runs the JAR like there's no problem.
Any ideas on how to make the JAR run on a machine with JRE installed?
Thanks in advance
Check packr
Packages your JAR, assets and a JVM for distribution on Windows, Linux
and Mac OS X
Appareantly, build for jre7 fixed the problem, why it can't run jre8, i don't know..
The JDK includes a tools.jar (among many others) which are omitted from the JRE. In your project expand the JRE System Libraries and make sure none of the libraries are coming from the a JDK.
Also adding some example text of the exact error you're seeing would really help us know what's going on. Stating "Java Exception occurred" is the equivalent of telling a doctor you don't feel well.
For what it's worth it's not a good idea to use classes from the JDK in your code as it has stricter licensing than the JRE.

Executing Eclipse plugin (jdt/ast) outside eclipse IDE environment

Can I execute Eclipse Java development tools as a standalone process? I need to get Java program's AST structure using Eclipse JDT from another program, and to do that, I need to execute eclipse plugin as a stand-alone process behind the scene.
Is that possible? If so, how one can do that?
Eclipse/jdt and eclipse/ast is nothing more than a jar file, so one can use them to build standalone java application.
Example
I googled to find ASTExplorer as an example to make eclipse/ast plugin as a standalone java project.
The program was targeted for pretty old eclipse (3.0.2), I downloaded the 3.0.2 for Mac OS X this site - http://archive.eclipse.org/eclipse/downloads/drops/R-3.0.2-200503110845/
You need to setup ECLIPSE_HOME classpath variables in Preference -> Java -> Classpath variables
The .classpath has those classpath variables already, you can refer to this post - .classpath contents update in eclipse. As you can see it refers eclipse/jdt(art) jar files. I'm pretty sure one can change the reference to the newest version of jdt/ast without downloading the 3.0.2 version.
As I use Mac, I need to replace the swt for PC with swt for Mac. I could do that in BuildPath/Configure Build path
First remove the PC swt reference.
Then add the correct Mac swt reference.
Compile the example with the eclipse indigo/on mac
When the setup is correct, eclipse starts building the project. You can use Project -> Build Project menu. Then, you can check the application works fine in eclipse.
Generate the executable jar
Export to executable jar file.
You'll get some warnings, but you'll have a jar file.
Execute the generated jar
Just executing java -jar ast.jar doesn't work on Mac, I got a hint from this post.
Running SWT based, cross-platform jar properly on a Mac
In short, you need to run java -XstartOnFirstThread -jar ast.jar
Does it have to be Eclipses's AST? Or is any AST generation o.k.? If it doesn't have to be eclipse, I'd suggest Habelitz open source Java AST Compiler. http://www.habelitz.com/ I'm using it myself for some projects....
Well, of course you can launch eclipse just like any other process : How to create a process in Java
And then the problem becomes relaying the information back to the original process, which gets kind of messy. My suggested approach in this case would probably be to create a plugin in eclipse and have that plugin do whatever it is you think you need the AST for. You can work out messages with command line options to eclipse, or a shared file or something.

Categories

Resources