run java program created in intellij from command line - java

I have a simple Java Maven program that I created in Intellij. It has Two classes Main and Read. I was able to build a jar and run it. However if I zip the source code into a folder , would I be able to compile it using command line? Something like javac ? How should I do this? Shall I run commands in Java folder in the project? Many thanks.

As far as the Java class loader is concerned, a .jar or .zip file is the same as a directory containing the the files, and .jar and .zip files are generally used to distribute compiled Java packages. Here you can read more about it.
For compiling the zip file: use the -classpath option to javac and java. We could, for example:
javac -classpath .:/users/johnr/java:/opt/jdk1.1.6/lib/classes.zip Hello.java

Related

how to use JDatePicker jar file into the program

I need to use 'JDatePicker' class for a program. I downloaded 'jdatepicker-1.3.2.jar' file. and when i extracted the file using the command "jar xf jdatepicker-1.3.2.jar", I got 3 folders in the directory " META-INF, tutorial, net". But i don't know how to import this to the java program and where to store this jar file and the extracted folders. could any one assist me on the above?
I don't use any IDE. I run the java programs in command prompt
You must have that exact jar file on the class path. When compiling specify jar in the compile
javac -classpath jars\jdatepicker-1.3.2.jar -sourcepath src\project -d classes src\project\MyProg.java

Need help building a Selenium Java Class file from cmd line

I'm trying to cmd line compile a .java selenium test script into a class file that I can run from the command line.
All of my selenium jar files and all other supporting jar and lib files are in C:\JarFiles
My CLASSPATH is set to C:\WDJarFiles*
I am working at the command line here: C:\EclipseIDEworkspace\MC3\src\Tasks
My .class files are located here C:\EclipseIDEworkspace\MC3\bin\Tasks and I'd like to be able to update them at that location.
My folder structure was set up by using Eclipse IDE so I'd like to keep the existing folder structure but now I want to be able to compile my .java files from the command line and update the .class files.
So, when I run javac like this:
javac Edit.java
It compiles OK and the .class file gets created in the same folder where I am running the javac command -- but -- I also get a huge number of other .class files in this same directory! These look like supporting class files.
I'm not sure what my cmd line javac syntax should be to:
Compile my .java file so its .class file gets updated in the C:\EclipseIDEworkspace\MC3\bin\Tasks folder.
I don't get all those other .class files created in my working folder C:\EclipseIDEworkspace\MC3\src\Tasks
Thanks for any help...
You should try the '-d' option to specify an output directory:
javac Edit.java -d ..\..\bin\Tasks
About the multiple other .class files, you probably have many nested classes into your Edit.java file?

Jar file won't execute, not sure if I'm creating it correctly

I'm trying to make a jar file out of two classes, one of which depends on an external jar. I have a directory with a manifest.txt, a lib folder containing the external jar RXTXcomm.jar, and a folder named Arduino containing my two classes, SendValue.java and SerialClass.java.
First I'm compiling my classes using:
javac arduino\*.java
This creates 3 new files, SerialClass$1.class, SerialClass.class and SendValue.class. To make the jar file, I'm running:
jar -cfm send.jar manifest.txt arduino\*.class lib\rxtxcomm.jar
This works fine. I then try to run the file using:
java send.jar
I get the error:
Could not find or load main class send.jar
I've also tried to run it with the following command, and got the same error:
java -cp . send.jar
The only line in my manifest.txt is :
Main-Class: Arduino.SendValue
My classes run fine in Eclipse, so I'm assuming they're not the problem. SendValue.java has the line:
public static void main(String[] ag) {
as it's supposed to.
Any ideas?
You want to run your jar using:
java -jar send.jar
Also, unless you want to do some magic with nested jars with some tool like OneJar, you should remove lib\rxtxcomm.jar from your jar command, and add the following line to your manifest.
Class-Path: lib\rxtxcomm.jar .
If you're going to use the command line or terminal for running a single java executable, then use
java -jar send.jar
Also it would be better if you went through compiling and testing using an IDE such as Netbeans, IntelliJ IDEA, or Eclipse as they're meant to do such stuff and are more reliable on doing the steps unlike the human brain.

Make File to run on Linux/ MAC OS to compile .Java Files to an exe form

I am a beginner in Java. I made my Java program using NetBeans. Now I have my .jar file.
But I would like to know how to write commands to compile .Java classes to .Class and then build a jar using those .Class files.
Does any one have an idea how to create a Make file/ Script for running on Mac to run my source code by compiling it itself.
I would use maven This will download dependencies, build you class files and build a jar for you.

how to convert .java file to a .class file

Can anyone tell me how I can convert a .java file into .class file with an executable bytecode?
A .java file is the code file.
A .class file is the compiled file.
It's not exactly "conversion" - it's compilation. Suppose your file was called "herb.java", you would write (in the command prompt):
javac herb.java
It will create a herb.class file in the current folder.
It is "executable" only if it contains a static void main(String[]) method inside it. If it does, you can execute it by running (again, command prompt:)
java herb
From the command line, run
javac ClassName.java
I would suggest you read the appropriate sections in The Java Tutorial from Sun:
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
Use the javac program that comes with the JDK (visit java.sun.com if you don't have it). The installer does not automatically add javac to your system path, so you'll need to add the bin directory of the installed path to your system path before you can use it easily.
To get a .class file you have to compile the .java file.
The command for this is javac. The manual for this is found here (Windows)
In short:
javac File.java
As the others stated : it's by compiling. You can use the javac command, but I'f you're new at java, I suggest you use a software for compiling your code (and IDE) such as Eclipse and it will do the job for you.
You can not compile any java file to class directly.
It should have main method to compile it in class file
After compiling it you can jar it.
java -jar AppName.jar
http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html

Categories

Resources