Javac 与 Java CommandLine Operations

Javac命令用于编译Java源文件,可以使用-options-来设置类路径、源代码路径和目标目录。-classpath或-classpath path指定用户类文件的位置,-sourcepath指定查找源代码的位置,-d directory设定目标目录。对于类路径,可以使用分号分隔多个路径。-g选项控制调试信息的生成,-Joption传递给java启动器。@argfiles用于包含更多选项和源文件的列表文件。源文件应按照包结构组织在目录中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Javac

 

javac [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]

Arguments may be in any order.

options

Command-line options.

sourcefiles

One or more source files to be compiled (such as MyClass.java).

classes

One or more classes to be processed for annotations (such as MyPackage.MyClass).

@argfiles

One or more files that lists options and source files. The -J options are not allowed in these files.

There are two ways to pass source code file names to javac:

  • For a small number of source files, simply list the file names on the command line.
  • For a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the javac command line, preceded by an @ character.

Inner class definitions produce additional class files. These class files have names combining the inner and outer class names, such as MyClass$MyInnerClass.class.

You should arrange source files in a directory tree that reflects their package tree.The source code for com.mysoft.mypack.MyClass should be in C:\workspace\com\mysoft\mypack\MyClass.java.

You can specify a separate destination directory with -d.

-d directory

Set the destination directory for class files. The directory must already exist; javac will not create it. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d C:\myclasses and the class is called com.mypackage.MyClass, then the class file is called C:\myclasses\com\mypackage\MyClass.class.

If -d is not specified, javac puts each class files in the same directory as the source file from which it was generated.

Note: The directory specified by -d is not automatically added to your user class path.

Non-standard options begin with -X.

-cp path or -classpath path

Specify where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH-cp nor -classpath is specified, the user class path consists of the current directory.

If the -sourcepath option is not specified, the user class path is also searched for source files.

If the -processorpath option is not specified, the class path is also searched for annotation processors.

Setting the class path

The class path is the path that the Java runtime environment searches for classes and other resource files. 

classpath1;classpath2

Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:

  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

The default class path is the current directory. Setting the CLASSPATH variable or using the-classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.

 

-g

Generate all debugging information, including local variables. By default, only line number and source file information is generated.

-g:none

Do not generate any debugging information.

-g:{keyword list}

Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:

 

source

Source file debugging information

lines

Line number debugging information

vars

Local variable debugging information

-Joption

Pass option to the java launcher called by javac. For example, -J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for -J to pass options to the underlying VM executing applications written in Java.

Note: CLASSPATH-classpath-bootclasspath, and -extdirs do not specify the classes used to run javac. Fiddling with the implementation of the compiler in this way is usually pointless and always risky. If you do need to do this, use the -J option to pass through options to the underlying java launcher.

-sourcepath sourcepath

Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

Note: Classes found through the class path may be subject to automatic recompilation if their sources are also found.

 

 

Java

java [optionsclassname [args]

options

Command-line options separated by spaces. See Options.

classname

The name of the class to be launched.

filename

The name of the Java Archive (JAR) file to be called. Used only with the -jar option.

args

The arguments passed to the main() method separated by spaces.

 

### IntelliJ IDEA Installation and Environment Setup Guide #### Installing IntelliJ IDEA To begin with, downloading and installing IntelliJ IDEA involves a few straightforward steps. One should visit the official JetBrains website to obtain the latest version of IntelliJ IDEA. After downloading, proceed through the installation wizard by following on-screen instructions provided during the installation process[^2]. For users preferring command-line operations or automated setups, alternative methods such as using package managers (like Homebrew for macOS) are also available but not covered within this guide. #### Setting Up Project Structure in IntelliJ IDEA Once installed, launching IntelliJ IDEA opens up an initial setup window where one may choose between creating new projects directly from here or opening existing ones. When starting fresh, selecting "New Project" leads into configuring project settings including choosing programming languages supported like Java among others along with specifying SDKs required for development purposes which ties back into ensuring proper configuration post-installation of JDK mentioned earlier[^1]. #### Configuring Environment Variables After setting up the project structure inside IntelliJ IDEA, correctly configuring `PATH` and `JAVA_HOME` environment variables becomes crucial especially when working outside IDE environments or integrating tools that rely upon these configurations being accurate. Typically, paths would point towards directories containing executables (`java`, `javac`) under `<java_install_dir>/bin` while `JAVA_HOME` points at root level i.e., `<java_install_dir>` itself depending on individual system architectures and preferences. Additionally, it is beneficial to ensure Gradle—a build automation tool—is properly configured either via embedded distribution offered by IntelliJ IDEA itself or standalone installations according to documentation guidelines found online. This ensures seamless integration between building processes managed externally yet synchronized efficiently within integrated development workflows facilitated by modern IDE features present in IntelliJ IDEA. ```bash export JAVA_HOME=/path/to/java/installation export PATH=$JAVA_HOME/bin:$PATH ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值