I made a .jar file using NetBeans. When I move it to any place on my laptop and double click it, it will work. When I try it on a different PC, it gives me a message box saying:
title: Java Virtual Machine Launcher.
text: A Java Exception has occurred.
Every PC i tried so far, gives me this. Those PCs do not have any additional Java software installed, only the basic one which updates itself automatically. If there is a way to share my Java file on different PCs, please tell me (even if this involves converting the file to some other format, but not that the user has to install anything extra).
Here is my error:
If in the PC where the program was created works, but in any other one fails, it seems it's a problem with some resource. Maybe you used an absolute path to find a resource file but that file is not in the jar. I think it works because the file can be found in your PC, but not in anyone else.
How about creating a bat file and setting java home inside it. So you could first set the home or path and then use java jar commands to execute the jar.
Related
I have a Java application exported into the executable JAR file, which I run from a Windows Forms app (via java -jar).
The solution works perfectly fine on my PC, but it won't run on other PCs. There is literally no output after running the JAR, no exception, no logs from log4j, the command line window closes without displaying anything.
I have:
confirmed that all paths used in both applications are relative
made sure the other PCs are using the same Java version
made sure that all required input files are in place
made sure the MANIFEST.mf is correct
tried running the JAR from command line - no output again
run the application with admin account
rebuilt the JAR several times
I have no ideas left at this point. Any suggestions are highly appreciated.
EDIT: the JAR was made in Eclipse on Windows 7. The other PCs I tried this on all have Windows 7 or 10. I do not use JavaFX or Swing, it is a purely console-based application.
After some experimenting I found the answer:
When calling the JAR from WinForms, I was passing a file path as argument. I didn't put \" at the beginning and end of the argument, so passing a path containing one or more spaces resulted in a wrong number of arguments.
It just so happened that the project path on my first PC didn't contain any spaces, that's why it worked there.
I have a selenium script written in Java. I exported it as a .jar file to my system and I can run that from my command line. But I need to send this across my team. The problem with the script is the task requires to get files from my computer using the file path and it need to do some conversion and save it back to a particular folder. I have written code with all the file paths for my computer. How can that run in another remote computer? Is there any way to do that? Also when i give the chromedriver path in my script it wont work on remote computer because they save chromedriver in different file location.
I tried using parameter but problem is it is a time consuming process. It would be great if some one can edit the jar file as a one time process. I used tools to open Jar file but the code is not seen it displays symbols.
You can try keeping all the required files (your files in your computer, chromedriver, etc) in the same folder as the jar that you are executing. This way, you can reference all the required files using a relative path, instead of an absolute one, i.e. ./your_required_file.txt
So, you can send the whole directory to your team to execute it.
That being said, I honestly recommend that you take some time on reading up on Java and Selenium's documentation.
A friend of mine once gave me a Java project on offline browser. It contains all class file as well as Java sources but I don't know how to run it or how can I check how it works . It doesn't contain any database or applet. please help
If you want to run a java .class file, open the terminal (if you are using Unix machine) or the command line (if you are using a Windows machine) and type java filename Note: filename does not include the .class extension, just use the name of the file and do not include the extension.
If you get an error this probably means you don't have java installed.
Import it into Eclipse or NetBeans and then click "run"...
That would be the simplest solution in my mind
I'm just a guy trying to learn some Java. The actual coding part works just fine for me, and until now I've been working in Eclipse (to new guys like myself, Eclipse is a really great free piece of software for writing and compiling code). But Eclipse compiles the code by itself, and I'm determined to learn how to do this without any training wheels, seeing as I'll probably need to do so someday. However, I already tried manually compiling my code with Command Prompt a few months ago, and ultimately I just got tired of banging my head against the brick wall. It seems that when I try to compile a simple HelloWorld file in cmd, everything that can go wrong, does go wrong. And it seems that I'm not the only one who keeps getting thrown off code because of this ridiculous first hurdle. Until now I've slowly been able to work around everything that keeps popping up, but this new problem is completely beyond any advice that I can find on the Internet.
I have my HelloWorld class ready to run. It is in the same file as my .java file. I have managed to compile it with the use of an environment variable specifying the location of the javac tool. Now all I need to do is invoke the java tool to run the file.
Creating a new environment variable specifying the location of java gives the following error message on cmd:
"Error: could not open 'C:\lib\amd64\jvm.cfg'"
I have no idea why it's picking this directory, leaping straight to \lib instead of going through \Program Files.
Specifying the location of the java tool in cmd, as my book tells me to do, gives the following error message:
"'C:\Program' is not recognized as an external command, operable program, or batch file."
which of course is only the case because I'm trying to specify the path leading to the java tool, whilst my command directory has already been confined to 'C:\Java Code', the location of my class file, which is necessary because that's the file I'm trying to run.
So in short, the only way around this I can see is to specify two command directories at once, which I'm pretty sure is impossible.
Solution
In my case, this was solved by two things; first re-installing Java. It seems that I was using the wrong architecture version (Oracle's site may have been assuming that my computer was 32 bit). This seemed to deal with the 'cannot find jvm.cfg issue'. Second, configuring the system variables as described in one of the responses and on this page
Right, I had exactly the same problem with compiling my code for the first time. jvm.cfg is always a difficult file. The way i fixed it was: To edit the PATH variable or JAVA_HOME to the path to jvm.cfg. jvm.cfg is a configuration file for java.
I'm learning Java and was trying to test my code on another machine but am running to the above error. I've looked at youtube videos, read forums(and SO) but still can't get this to work.
I basically wrote some code on my mac using eclipse that referenced an external jar file. I have that jar in my lib folder and have added it to my build path in Eclipse via right-click "Build Path -> Add to Build Path". The code works fine on my laptop.
But when I try to run it from a linux command line, I get the above error. I am taking the code from eclipse and copying it to a file(first_try.java) and then run this commands:
CLASSPATH=./jedis-2.0.0.jar;export CLASSPATH
javac first_try.java
java -classpath . first_try
but then I get the error: Exception in thread "main" java.lang.NoClassDefFoundError: redis/clients/jedis/Jedis I downloaded the program via wget and checked permissions and tried different variations. There was a similar question I found(out of the many related ones) that had a similar context as mine but it worked for the user to just type java filename (which is not working for me)
I am learning a bit of java code but have never been successful at running external jars. I'm wondering what I'm doing wrong and what I can do to permanently fix it(ideally I want to write code locally and then copy it and test it on another machine like this)?
Or is there a better way to deploy code that depends on third party jars to other systems?
You are building your class path env var but then you don't use the value in your java command. You need $CLASSPATH instead of the dot after -classpath
Good luck learning java, I have enjoyed using it for over 10 years now ;)