I am using a .bat file, which is reliant on a .jar file. I have java (jdk/jre) installed on my system. If I run a command on this command line api via cmd (e.g. nscmd --help), everything works fine.
However, I want to run commands inside another program (Automise www.automise.com). If I do so, with the command line tools in another folder to Java, I get the infamous "java is not a recognised keyword...etc" error. If I put the command line tools in the same folder as Java, I get this error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Program returned code : 1
How can I successfully run the command line tools?The tool is this: http://www.newservers.com/language/en/documentation/reference-nscmd.html
Thanks
Add the directory java is in to your path variable.
Related
I have a bat file I run through command prompt to deploy a java app locally for local testing on my machine:
start java -server -AnotherParameter -AnotherParameter -jar path\to\jar\appName-version.jar
exit
To run this bat file, I use the following command:
start batFileName.bat
However, the next time the version changes on this jar, the bat file will not work, because the version is out of sync. This results in myself having to change my bat file each time the version is updated.
Is there a way to pass in a the version when I run the start command through command prompt to use as the jar name? This way when I run my bat file, I can just pass in the name of the jar at that time to run the java application? If so how would I pass that version into the bat file and how would I use that parameter?
In your script, replace the version part of the jar file name with an argument replacement parameter:
start java -server -AnotherParameter -AnotherParameter -jar path\to\jar\appName-%1.jar
Do not start the program using java -jar . Change the start up script
include the folder where you jar file is present into class path with wild card, like:
java -cp path\to\jar*
call the main class in your jar file. I suppose the main class does not change so often as versions of the jar file?
The whole command line will look like this:
java -cp path\to\jar* com.something.foo.bar.Main
JVM will load your jar whatever its name is, and will find the main class and will start it if it has "main" method.
I want to run my Java code in remote server with external jar file. I referred to this tutorial and run IntelliJ IDE to generate a jar file of my whole project. Now I can run the following code in local terminal successfully.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
java -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try
The code will run successfully. However, when I try the same thing in server. The compile process can be finished without any errors or warnings.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
I have checked that the class file new_server_try.class is generated in the directory.
However the second step will return error as Could not find or load main class new_server_try and I am not sure why this happens.
on the second command try giving the full package name .. like shown below
java -cp "/Users/natsuapo/out/artifacts/main_jar/main.jar:lib/*" my.package.MainClass
also with operating system the command differs, check below
Windows
java -cp "Test.jar;lib/*" my.package.MainClass
Unix
java -cp "Test.jar:lib/*" my.package.MainClass
I made a program in Java on my Macbook. It compiled and executed properly.
I took the .class file and tried to run it in an another machine with windows on it.
I wanted to examine the platform independent feature of Java.
It first gave me Java launcher error and then kept saying, main class not found.
I did run the program on my Mac using the terminal with the following commands javac file.java
and executed it with java classname
Took the class file and tried to run in a windows machine using the command line with the command java classname.
Things did not run then
Has nothing to do with the OS, if java is installed on the windows machine, the class files should run. First make sure you have the JVM installed, if that's not it, it is because your are not running your main class.
Run main from cmd with this command.
java -cp "ClassPath" FileName
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
I have a .java file which i compiled in a package named "Mypack",using command line as follows
javac -d . file_name.java // The "." specifies the current working directory which was the desktop
so it creates a folder on the desktop named "Mypack"(The package name), in the folder the .class file for my program is placed.Now i did the following
java -classpath "C:\Users\LoRd CuRZon\Desktop\Mypack" file_name // Error Could not find or load main method
Even if i go into the directory "Mypack" and launch command prompt from that directory and try to run the program i still get the same error.
run it as likewise from Desktop,
c:/.../Desktop> java Mypack.file_name
java command requires fully qualified name .
so from desktop run java Mypack.classname
If you have this error:
Error Could not find or load main method
That means you don't write a main method in you code try to write it.
But befor to do those steps:
Fo compiling a programme do this:
java Mypack.file_name
To run it do like this:
java Mypack.classname