March 24, 2016 10:10:39
1. Export the project to a jar package.
One thing to note here is that there is no concept of source folder in the JAR package. Select an item, right-Export,jar file, next, select our exported files
, selected, SRC, and Design two Soruce folder, but only in our export jar, the file name of the package construct. There is no src this file name and design this filename.
// This code, get the. class file directory, which is the bin directory. GetClass (). getClassLoader (). GetResource (".")
Differences between exported to jar file and runnable jar file
export Jar file: will let you choose to export the directory, you select all Soruce folder just export the corresponding bin under the compiled file.
Export runnable JAR file: will not let you choose the exported file directory, the default is to export only the bin directory (out of all the Soruce folder), but let you specify the main method all classes are that one.
This export method is added in the Manifest.mf file.
Main-class:com.udv.main.appmain
Class-path:.
Note: The configuration file inside the jar file is not read, (a test is done here, and a file is prepared in a package of the jar file, and a configuration file is also available to the directory, and the configuration file is loaded when it is run).
Note: When a project references another jar, the Runnable jar file creates maven-related things.
When exporting Soruce folder, the configuration below Soruce folder will not be executed inside the jar and will be extracted.
// There are two problems with using this notation to get a configuration file: // 1,myeclipse is the bin directory of the project, even if there is this file in the bin directory, but still error // This code in 1.linux gets the JVM class plus path, which is not your project classpath getclass (). getClassLoader (). GetResource (".") + "Config.properties";
Add a little bin below the first level directory is the SRC directory, the bin directory under the level two directory, must be the directory of the package structure.
configuration file path:
New File ("Config.properties");
1, the MyEclipse represents the Config.properties file in the directory with the project.
2, at runtime, is represented in the same directory as the jar file.
─jarfile
├─hawei.jar
├─config.properties.
New File ("Etc/config.properties");
1, in MyEclipse represents the Config.properties file in a source folder called etc
1, the runtime means: if
─jarfile
└─hawei.jar
└─etc
└─config.properties
How to run two methods of exporting files (without relying on other jars)
1,runnale JAR file can be run directly with Java Xxxxx.jar.
Note, however, that the configuration file directory is not properly
2,jar file
1,JAVA–CP Xxxxx.jar Com.udv.main.AppMain So you can run it. (This is only possible without the use of other reference packages)
This kind of operation has the same effect as the operation. Just unzip the jar file (equivalent to copy the entire bin directory) and then use the command
Java Com.udv.main.AppMain This action is the same as the above effect. (here to enter the project with this directory, not Com/udv/main/appmain is the form of documents)
As you can also run directly with the main method of the class file first CD Com/udv/main and then direct Java Appmain (this is not possible, you must be in the project with the directory under the Run)
Note: Run the jar file directly,
So the jar file is in the same sibling directory as the project directory.
If you extract it and run it,
The same sibling directory as the COM (top-level package name) folder is the project and directory.
Here is a case of referencing a package
1, can be set directly under the MAINFEST.MF file (usually not in this way)
If there are many items in the Class-path, the line too long will be error when it is written in a row, then it is necessary to write class-path in multiple lines. Note: Starting with the second line, you must start with two spaces
(I didn't)
2, with command JAVA-CP Lib/jedis-2.6.1.jar:bjar.jar:cjar.jar Com.udv.main.AppMain (class of Main)
Note: The jar is separated from the jar with a: number to open,
The above code introduces three Jar.jedis-2.6.1.jar and Bjar.jar and Cjar.jar if Bjar and Cjar have a package structure like Com.udv.mian, there are appmain classes, That jar executes the Mina method in that class in front of it.
3, if it is a direct copy of a bin directory, with the following script to start.
Extended Knowledge:
Java-jar Loginadd.jar ***.xls&
Nohup Java-jar Loginadd.jar ***.xls&
Note: 1, in the application of unix/linux, we generally want to let a program run in the background, so we will often use & at the end of the program to let the program run automatically. If it is not added to the console, the close window or CTRL + C will stop executing.
2, Nohup: The standard output of the program is automatically redirected to the current directory of the Nohup.out file, played the role of log
Linux uses scripts to start Java Engineering (non-web engineering)-the kind that introduces many jars
http://lavasoft.blog.51cto.com/62575/204713 (script method launches direct copy bin directory)
Scripting way to start jar (and success)
March 26, 2016 23:27:17--not finished
Running Java projects under Linux