blob: aef6ec9a4ef15c039c2040e57ffa7503d0b7549c [file] [log] [blame]
<?xml version="1.0"?>
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
<title>Jakarta Commons JCI - Usage</title>
<author email="">Commons Development Team</author>
<section name="Compilation">
The <code>JavaCompiler</code> is quite simple. You have to provide the paths to
the sources, where to get the sources from and where to store the classes. Then
you just pick one of the compilers to do the work. The result of the compilation
is returned as <code>CompilationResult</code>.
JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse");
CompilationResult result = compiler.compile(sources, new FileResourceReader(sourceDir), new FileResourceStore(targetDir));
System.out.println( result.getErrors().length + " errors");
System.out.println( result.getWarnings().length + " warnings");
Information like line numbers of errors etc are accessible in a consistent way.
If supported by the compiler you can even get notified about error before the
end of the compilation. (see the <code>CompilationProblemHandler</code>) for that.
The <a href="">example subproject</a>
provides a simple <a href="">JSP servlet</a>
and a javac-like <a href="">command line interface</a>.
<section name="Filesystem monitoring">
A subproject of JCI provides a <code>FilesystemAlterationMonitor</code> that can
be used to get notified when files change on the local filesystem. If you attach
a <code>ReloadingListener</code> or a <code>CompilingListener</code> it can even
trigger the reload of a class in the <code>ReloadingClassLoader</code>.
ReloadingClassLoader classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
ReloadingListener listener = new ReloadingListener();
FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();
fam.addListener(directory, listener);
But you can also just implement a simple <code>FilesystemAlterationListener</code>
yourself and just use it to get notified about configuration files changes
<a href="">for example</a>.
The example just extends the <code>FileChangeListener</code> that provides a few convenience methods.