A great feature introduced with the JDK 6 is the improved classpath syntax for including Jars of a specific directory. This allows you to do this
javac -cp "lib\*" MyClass.java
java -cp "lib\*" MyClass
from the command line without using a build system like Maven or Ant. But each of you who has to build and run Java classes with the JDK 5 or earlier and suffer from some project restrictions that reduces the set of tools to the ordinary command line will have to build the proper classpath by naming each Jar separately:
javac -cp "lib\jar1.jar;lib\jar2.jar" MyClass.java
java -cp "lib\jar1.jar;lib\jar2.jar" MyClass
On a Unix based system one could use glob in a shell script. The doomed Windows users can either use some shell replacements or have to build the command line with the arguable help of batch files. This blog post serves as a reference for those who stumble across loops and delayed expansion of variables in Windows batch files. To make the story of a bumpy road short here is the working solution for Windows XP:
REM needed to overcome weird loop behavior
REM in conjunction with variable expansion
SETLOCAL enabledelayedexpansion
REM construct classpath of seperate jars
cp=explicitlyKnownJar1.jar;explicitlyKnownJar2.jar;
FOR %%F IN (lib/*.jar) DO (
SET cp=!cp!;lib/%%F%
)
javac -cp "%cp%" MyClass.java
java -cp "%cp%" MyClass
Another Sample:
@echo off
setLocal EnableDelayedExpansion
set CLASSPATH="for/R ./lib %%a in (*.jar)do(
set CLASSPATH=!CLASSPATH!;%%a
)
set CLASSPATH=!CLASSPATH!"
echo !CLASSPATH!
Please note that you should select the needed Jars carefully since Windows XP cannot handle environment variables longer than 8KB. Try to use relative files names to “solve” this issue. If relative paths are no option you could try to use virtual drive letters instead.
Anyway, my advice is: Convince your “build manager” that you need a true build system in order to ensure the product quality and safe hours of work (around) time. In Eclipse a first draft of such an Ant script could be produced using “Export… Ant Buildfiles”.
相关推荐
详细讲解了java classpath 的详细过程,让你不在为配置java环境而烦恼,讲的非常好!word格式的!
linux bash: YOUR_LIB=your_path ... windows : SETLOCAL ENABLEDELAYEDEXPANSION set LIB=xx set CLASSPATH=. FOR %%C IN (LIB\*.jar) DO set CLASSPATH=!CLASSPATH!;%%C echo %CLASSPATH%
java classpath 理解 包括 1 在命令行查看classpath 2 在命令行设置classpath 3 classpath理解 4 命令行中直接使用classpath 很经典哦
Java环境配置与设置JAVA_HOME_CLASSPATH_PATH的目的
本人在学习java的过程中深受classpath的折磨,为了让初学者少走弯路,我将这些经验总结了一番,总结了多种classpath的基本使用情况和常见的一些问题,以及解决方案和原理,供大家参考
java classPath checker eclipse myeclipse
java classloader classpath 张孝祥
一份详细解释java的classpath和package的含义和配置方法的文档。
NULL 博文链接:https://foreversky12.iteye.com/blog/2325785
13-Java语言(classpath环境变量
在Windows系统上设置classpath环境变量的方法; 在macOS和Linux系统上设置classpath环境变量的方法。 内容概要: classpath环境变量详解; 设置classpath环境变量(Windows)的步骤; 设置classpath环境变量(macOS...
Java 的新入门者对classpath往往比较困惑,为何在开发环境中能运行的东东出去就不好,或在外面运行的东东挺溜的进了开发环境就死菜,烦死了! 看完俺这篇文章包您万事无忧
Java程序调优---去掉 java 项目中 多余的jar包 两个插件 一、ClassPath Helper 说明: 1.depends on:表示该类依赖于下面的jar包列表。 2.refrenced by:表示该类被下面的jar列表所依赖。 3.unresolved references:...
在linux和windows下动态设置classpath调用java类方法,绝对简单实用.包括实例子和文档.
关于java的classpath补充,详细说明如何配置classpath,如火热让javac正确编译运行java文件
classpath 和path
1.windows 安装 新建JAVA_HOME,变量名:JAVA_HOME;变量值:D:\jdk; 新建CLASSPATH,变量名:CLASSPATH;变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar 修path,%JAVA_HOME%\bin;%JAVA_HOME%\jre\...
.classpath
环境变量配置 环境变量配置 1 理解环境变量的作用 2 学会配置环境变量 对于Java程序开发而言,主要会使用JDK的两个命令:javac.exe、java.exe ...Java虚拟机就是通过ClassPath来寻找类的字节码文件。 JAVA_HOME 配置步
JAVA坏境变量中的JAVA_HOME path classpath 的设置与作用解释 适合初学者