Running an executable jar file using Eclipse - java

I have a project file which includes a jar file(monix.jar) and some data(models, plugins, ...). Developers didn't provide source code of it and I need to run it.
I'm working in the eclipse env and I tried this steps:
extracted it in my eclipse workspace(it was extracted under a folder named monix)
in the eclipse:Run > External Tools > External tools Configurations
set location in the Main tab to: D:\eclipse workspace\monix\data\gate\plugins\ANNIE\build.xml (and ofcourse I tried this path too: D:\Program Files Project\Java\bin\java.exe) by Brows File System button.
then set Working Directory to the path of project folder. D:\eclipse workspace\monix by Brows File System button.
Developers have provided a syntax for running it ($ ./monix inputDirectory outputDirectory) so I set Arguments according to this syntax ($ ./monix D:\monixinputs D:\monixoutput)
When I run it, there is an error:
Exception occurred executing command line.
Cannot run program "D:\eclipse workspace\monix\data\gate\plugins\ANNIE\build.xml" (in directory "D:\eclipse workspace\monix"): CreateProcess error=193, %1 is not a valid Win32 application
I'm totally confused and really need your help,Thanks in advance.

File.jar
If you want only run the program you have to use this file. For run it open cmd or bash in Windows or Linux and write:
java -jar /Path_Of_Your_File/File.jar
(Be sure that you have environment variable "JAVA_HOME" correctly configured)
Build.xml
This isn't for run the program. This file is used, for example, for generate File.jar from the Java code.
Run --> Run configuration in Eclipse
Here you have to specify the name of your project and the name of the main class in your project, but if you haven't the code, you don't have to use this.
D:\Program Files Project\Java\bin\java.exe
This is java.exe, the virtual machine of Java, you don't have to execute this for run your project.

Related

How to determine which command Netbeans is executing to run the project?

I'm developing an Java application using Netbeans and Maven. I'm struggling a lot to run the project as standalone application. Launching the project from Netbeans is all fine but running the executable jar yields an error (failing to load a data file).
I need to know exactly which command(s) Netbeans is executing to run the application. However, the output window of Netbeans only shows me what the application writes "back". Is there a way to figure out/display the command(s) that Netbeans is using to run the project?
Thanks
EDIT: Running the java application and loading files is not the issue here. I'm able to run the application and the libraries are loading correctly. The issue here is to understand how Netbans runs the application (by looking at the commands that are executed).
Netbeans outputs the command it invokes as the very first line of the output.
I use Netbeans 8.2 and that's how it looks like when I hit big green Run button in maven project:
The first line reads (formatted for better readablility):
cd D:\test;
"JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_112"
"M2_HOME=C:\\Program Files\\apache-maven-3.3.3"
cmd /c "\"\"C:\\Program Files\\apache-maven-3.3.3\\bin\\mvn.cmd\"
-Dexec.args=\"-classpath %classpath com.test.AppStarter\"
-Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_112\\bin\\java.exe\"
-Dexec.workingdir=D:\\test\\target\\dist
-Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\"
-Dfile.encoding=UTF-8
org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
From that line I can tell that Netbeans:
goes to the project's directory
sets environment variables (JAVA_HOME and M2_HOME)
then executes cmd that executes mvn (by its full path)
with bunch of -D arguments (which specify working directory and AppStarter as a class to execute)
and exec-maven- plugin with target exec.
When NetBeans compiles a program it creates a folder-hierarchy with compiled .class files. When creating a JAR archive ZIPs those into the archive. When executing the program, (or debugging,) NetBeans runs the .class files off the folders, not in the JAR file.
These could cause different problems, like different PATH. This can cause "file not found" errors with relative paths.
what is your operatingsystem?
windows:
then wmic may be the tool, which could show you the complete commandline. you will find examples here command line of process by name
linux:
try
ps -ef | grep java

Can't open a java file in terminal

I have java installed but when I try to open it in terminal it doesn't work
I type
java -jar Minecraft.jar
the output I get is
unable to get access to jar file Minecraft.jar
How I could fix this so I can next time just click the app. My operating system is Linux
Minecraft.jar file must be in your current working directory, which seems not being the case. So you either change your working directory to where Minecraft.jar resides or give full path to it
java --jar /your/valid/full/path/to/Minecraft.jar
give the full path to jar or go to directory and run command java -jar Minecraft.jar.

Unable to run .jar files by double-clicking them on Windows 7

Running a .jar file in the command line works fine, but I am unable to execute .jar files on my PC by double-clicking them. What is interesting, the same .jar files successfully execute on my laptop with a double-click.
I included %JAVA_HOME\bin and JDK_HOME\bin in the PATH variable.
I have JAVA_HOME set to C:\Program Files\Java\jre1.8.0_121.
I have JDK_HOME set to C:\Program Files\Java\jdk1.8.0_121.
For some period of time, the Java(TM) Platform SE binary disappeared from the Open with list, and I could not add it until I changed the HKEY_CLASSES_ROOT\jar_auto_file\shell\open\command key in regedit.exe to the appropriate version:
C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" "%1".
Here is a snapshot of Windows CMD with java -version entered on my PC:
I tried the following methods, with no success:
reinstalling both JRE and JDK,
associating .jar files with C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe,
using assoc .jar=jarfile and ftype jarfile="C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" -jar "%1" %* in command line,
creating a new system Environment Variable OPENDS_JAVA_ARGS and setting it to -jar.
Additional information:
I am using Windows 7 Professional 64-bit (Service Pack 1) with latest
updates installed both on my PC and laptop.
Running .jar files by double-clicking them used to work on my PC,
but suddently stopped working some time ago. I did not modify
anything related to Java.
I have the newest version of both JRE and JDK (Java 8 version 121).
Of the .jar files I am trying to run, some are GUI Swing applications
and some open the system console (if not already open) using
Runtime.getRuntime().exec(String[]).
I have already tried fixing this problem with solutions on the following links (without success):
How to run .jar file by double click on Windows 7 (64)
How to open/run .jar file (double-click not working)?
I can run .jar files through cmd, but I cannot double click them
Can't Run JAR Files
Notes:
I do not want to open .jar files with WinRAR.
I do not want to open .jar files by running java -jar jarfile.jar in cmd.exe.
I am not looking for a 3rd party application to run .jar files.
For now, I am using C:\Windows\System32\cmd.exe /k "java -jar C:\path\to\jarfile\Program.jar" as a shortcut location to run jar files, but I am not satisfied with this solution as this opens the console to run even Swing applications.
I managed to get Java(TM) Platform SE binary (javaw.exe) in the Open with list by matching paths in HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE registry entries:
HKEY_CURRENT_USER\Software\Classes\jar_auto_file\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command
Seems like one of the entries pointed to an older version of Java. Now .jar files are finally showing icons, but still do not work on double-click.
UPDATE: SOLUTION
Delete the .jar and jar_auto_file entries from HKEY_CURRENT_USER/Software/Classes and it should work. .jar files should open on double-click again.
Make sure to backup these entries first by right-clicking the entry and choosing Export.
Additional information can be found on superuser.

jar file is not executing on double clicking on windows 7

I have CQ5 executable jar file.It is suppose to be executed on double clicking.But i get error saying "could not find Main class program will exit".The same jar file executed on all my team mates machine but i am unable to execute it.
I am working on windows 7 OS.
I have jre6 installed.
I have done all steps provided in following link .jar file keeps giving me " could not find the main class". Program will exit.
my ftype and assoc is set to propervalue.
there is no problem in manifest file(becoz it executed on others machine).
all my path variables are set properly.
type of file on my system is "JAR" but on everyone else machine its "Executable JAR"
Could not figure out what is problem with my system.
Help plz.
You can alternatively try executing this command from a command console,
first CD to the location where you have the jar file and execute
For Win7 32-bit:
java -Xmx1024M -jar .jar
For Win7 64-bit:
java -XX:MaxPermSize=256m -Xmx1024M -jar .jar
if you have supported version of Java installed correctly, then the command should be able to start the CQ5 server. In that case, for fixing the double click issue, you would need to fix the filetype association of .jar files to open with /bin/javaw.exe
For supported Java versions, refer
CQ5.5 http://dev.day.com/docs/en/cq/5-5/deploying/technical_requirements.html
CQ5.6 http://dev.day.com/docs/en/cq/5-6/deploying/technical_requirements.html

Build for JavaFX project not creating exe

I am trying to build a exe file for my JavaFx project. The project is wrote in Java 6 and i have downloaded the standalone JavaFX for Java 6.
When i try to build the build.xml file using ant it is successful but does not create the exe I think it could be because of this message before it completes the build.
Skip [Exe Bundler (based on Inno Setup)] due to [Java Runtime does not
include lib\jfxrt.jar]
How do I go about fixing this?
EDIT:
Fixed How to change JAVA.HOME for Eclipse/ANT
A better solution might be to use the build.xml to output a jar file. Then create a text file then rename it to .bat file that executes the jar. It is pretty straight forward, and if you want to be fancy make an installer that creates shortcuts to the bat file. The contents of the bat file should be as follows (the sample will remove the console from showing up, but if you want the console use java instead of javaw):
#echo off
rem ***** Memory Initialization args *****
SET MYPROPS=%MYPROPS% -Xms512m
SET MYPROPS=%MYPROPS% -Xmx1024m
#echo on
START javaw %MYPROPS% -jar <project_jar>.jar com.example.Main
#echo off

Categories