A environment:
1. linux
2. There are two java classes, A.java and B.java, all in the same directory
Second Source:
A.java
-
package com.abc;
-
public class A {
-
public static void test() {
-
System.out.println( "A:test()");
-
}
-
}
B.java
-
com.abc.A amount;
-
public class B {
-
public static void main(String[] argc) {
-
A a = new A();
-
a.test();
-
}
-
}
III. Compile and run
-
# Compiler
-
javac -d . A.java B.java
-
-
#run
-
java B
-
-
# Output
-
A: test()
IV. Not in the same directory
To link ahead of each file (make_file (content): COM / filetool / util / A.java
COM / filetool / main / B.java)
javac -source 1.7 -target 1.7 -d $APP_HOME/code/ecs/bin -encoding UTF-8 @$MAKE_FILE
two.
jar package class files, how to run dos command line?
If I do not run the main class jar package,
I want to run another jar file a class package.
Contents are as follows:
dist
config.xml
SendMessage.jar
I want to run SendMessage.jar in Test.class file called from the command line, if realized, do not unpack.
I want to run another jar file a class package.
Contents are as follows:
dist
config.xml
SendMessage.jar
I want to run SendMessage.jar in Test.class file called from the command line, if realized, do not unpack.
Enter cmd
into the directory where you SendMessage.jar
execute java -cp SendMessage.jar Test.class
if Test.class have the package name, then the following
java -cp SendMessage.jar mypackagename.Test.class
into the directory where you SendMessage.jar
execute java -cp SendMessage.jar Test.class
if Test.class have the package name, then the following
java -cp SendMessage.jar mypackagename.Test.class
three.
After the application labeled jar package through maven, jar can be performed by java -jar ***, main method will run the specified mainly in MANIFEST.MF main method specified; so if there are multiple main method of time how to run the specified main method which, by the following command to execute Java -classpath ****. JAR **** ****. className [args] **** herein. **** means is the package name; **** class name is className;. args parameter passed in the finger; sum up: there are two cases run the jar 1> maven after the main packing method specified by the MANIFEST.MF Java-jar-Service--jar Mplus -with-dependencies.jar if maven, you can add the following code to specify the main method pom.xml <Build> <plugins> <plugin> <the groupId> org.apache.maven.plugins </ the groupId> <the artifactId> Assembly-plugin-Maven </ the artifactId> <Version> 2.3 </ Version> <Configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>io.test.main.MainOfDiskMount</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </ Execution> </executions> </ plugin> </ plugins> </ Build> mainly inside mainfest this code block; package name + class name specified in the main method mainClass executed; maven package and specify the command, it can be seen that package the jar in the META-INF MANIFEST.MF add the contents of a content there is the main method we specified in the pom.xml; then packaged into a jar run time, if you want to add parameters, added directly behind it it; Java-Service-Mplus -jar JAR-with-AAA-BBB dependencies.jar 2> if not specified in the MANIFEST.MF, jar in a plurality of main method, the run command specifies a particular main method java - cp mplus-service-jar-with -dependencies.jar com.smbea.dubbo.bin.Console aaa bbb and then the main method to add logic to print, the execution parameters situation is actually the AAA, bbb value as args parameters passed into it; summary: maven items packaged into the JAR, then run the main method, there are two cases, one is the main method specified in the MANIFEST.MF run; the other is designated to run from the command line mai A method of packet n; and can add transmission parameters corresponding to the main method;