Gobliins
Gobliins

Reputation: 4026

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

Upvotes: 0

Views: 353

Answers (2)

vic vic
vic vic

Reputation: 78

On linux you should use :

CLASSPATH = path1:path2:...

Oracle documentation:

Linux

Windows

Upvotes: 2

AlexR
AlexR

Reputation: 115378

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

Upvotes: 1

Related Questions