1

'Problems encountered while deleting resources' for Zk-Spring-Boot project

asked 2018-06-11 11:24:30 +0800

huionn gravatar image huionn
11 1

I am new to ZK. We will use Zk + Spring Boot in our new project. For convenience, I prefer to run web application directly from eclipse/sts (spring tool suites).

Issue:

In Windows OS, when running Zk + Spring Boot application (github.com/zkoss-demo/zk-spring-boot) using STS, I encounter error "Problems encountered while deleting resources." after I modified a ZUL file (that has been viewed previously). When this happens, i have to stop the server and clean up the project.

(I tested that there is no issue when running normal Zk application in STS.)

Finding:

After some troubleshooting, I found that the zul files are locked from deletion by method getLastModified(..) in ExtendletLoader and ResourceLoader. sun.net.www.protocol.file.FileURLConnection implicitly open input stream when getting the last modified date and hence lock the file in Windows OS. I read from other forum that to workaround this issue, the input stream need to be explicitly closed.

/** Returns the last modified time.
 */
public long getLastModified(String src) {
    if (getCheckPeriod() < 0)
        return 1; //any value (because it is not dynamic)

    try {
        final URL url = getExtendletContext().getResource(src);
        if (url != null) {
            URLConnection urlConnection = url.openConnection();
            try {
                final long v = urlConnection.getLastModified();
                return v != -1 ? v : 0; // not to reload (5.0.6 for better performance)
            } finally {
                try {
                    InputStream inputStream = urlConnection.getInputStream();

                    inputStream.close();
                } catch (IOException ioe) {
                }
            }
        }
    } catch (Throwable ex) {
    }
    return -1; //reload (might be removed)
}

I patched the zweb-8.5.0.jar and it resolved the issue. This post may help whoever interested in using zk + spring boot for development.

(for normal Zk application, src.url is null. So the file last modified data is accessed though src.file.lastModified(). I guess that as spring boot has unique package (jar), its resource loader is different.)

delete flag offensive retag edit
Be the first one to reply this discussion!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2018-06-11 11:24:30 +0800

Seen: 6 times

Last updated: Jun 11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More