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

2 Replies

Sort by ยป oldest newest

answered 2018-06-26 18:41:17 +0800

cor3000 gravatar image cor3000
4158 1 7
ZK Team

updated 2018-06-29 16:36:59 +0800

thanks for mentioning the problem and patch. Since we are trying to improve the spring boot support I created a JIRA ticket here: http://tracker.zkoss.org/browse/ZK-3973

In case you have additional resource links regarding this issue, please add them here or to the JIRA ticket directly.

Another occasion for this problem I encountered was related to Jetty and the workaround for development was setting a specific jetty init parameter like this:

https://github.com/zkoss-demo/zk-gradle/blob/master/jetty-dev-context.xml#L30

Robert

UPDATE: ZK-3973 will be fixed in 8.5.2 (testable in 8.5.2.FL.20180628-(Eval))

link publish delete flag offensive edit

answered 2018-08-13 03:03:38 +0800

AndrewPizzey gravatar image AndrewPizzey
1

I've read the book and really enjoyed it.

link publish delete flag offensive edit
Your reply
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
1 follower

RSS

Stats

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

Seen: 15 times

Last updated: Aug 13

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