0

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

Community
  • 1
  • 1
Gobliins
  • 3,848
  • 16
  • 67
  • 122

2 Answers2

2

On linux you should use :

CLASSPATH = path1:path2:...

Oracle documentation:

Linux

Windows

dguay
  • 1,635
  • 15
  • 24
vic vic
  • 78
  • 1
  • 6
1

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

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Is there a possibility that i can generate a working CP system independently? – Gobliins Oct 27 '15 at 12:57
  • Please clarify your question. Do you mean that you want to create script that runs on any platform and generates classpath following rules of current platform? – AlexR Oct 27 '15 at 12:58