简体   繁体   中英

JavaCompiler classpath Windows vs Linux

I want to make a tool that can generate and compile java source code and generate a jar file from it:

For this i use the JavaCompiler:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

When i add the classpath to the Java SystemCompiler:

optionList.addAll(Arrays.asList("-cp", classpath));

it works for Windows when i setup my classpath with ";" as seperator:

classpath = "jar1.jar;jar2.jar;dir/jar3.jar;dir/jar4.jar";

In Linux it fails.

When i use space instead of ; like:

classpath = "jar1.jar jar2.jar lib/jar3.jar lib/jar4.jar";

it fails for both systems.

Same goes for:

classpath = "lib/*"

I would need a solution that can generate a working classpath system independently.

UPDATE (Solution):

Ok i found out that there is a java offers

File.pathseparator 

Which changes corresponding to the System Environment.

See also File.separator or File.pathSeparator

On linux you should use :

CLASSPATH = path1:path2:...

Oracle documentation:

Linux

Windows

Use : on linux instead of ; that you are regular to use on windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM