<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to get webcontent folder in ivy project</title><link>https://answers.axonivy.com/questions/2143/how-to-get-webcontent-folder-in-ivy-project</link><description>&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;Sometime i want to lookup some resources in webcontent folder of current ivy model. then i com up with this code snippet. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static String getFolderInWebContent(String folderName) throws Exception {
    String rootFolder = getProjectRootFolder() + "/webContent/";
    if (folderName != null &amp;amp;&amp;amp; !folderName.isEmpty()) {
        if (!folderName.endsWith("/") &amp;amp;&amp;amp; !folderName.endsWith("\\")) {
            folderName = folderName + "/";
        }
        File f = new File(rootFolder + folderName);
        if (f.isDirectory()) {
            return f.getAbsolutePath();
        }
    }
    return rootFolder;
}

public static String getProjectRootFolder() throws Exception {
    return SecurityManagerFactory.getSecurityManager().executeAsSystem(
            new Callable&amp;lt;String&amp;gt;() {
                @Override
                public String call() throws Exception {
                    return Ivy.request().getProcessModel()
                            .getReleasedProcessModelVersion()
                            .getProjectDirectory();
                }

            });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I hope it's helpful for someone who need it or if you have a better solution, just drop here. i also want to extend  my knowledge about ivy.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2143/how-to-get-webcontent-folder-in-ivy-project" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 27 Oct 2016 12:30:32 -0400</lastBuildDate><item><title>Answer by trungdv</title><link>https://answers.axonivy.com/questions/2143/how-to-get-webcontent-folder-in-ivy-project/2145</link><description>&lt;p&gt;i just got this solution from @hau.tran(TA of axon active vietnam). i think it's better :)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import org.eclipse.core.resources.IFolder;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.security.internal.SecurityManager;

public class WebContentResourceLoader {

    public Path getResource(String relativeToWebContent) {
        return findResource(relativeToWebContent)
                .orElseThrow(() -&amp;gt; new RuntimeException("Resource at webContent/" + relativeToWebContent + " cannot be found"));
    }

    public Optional&amp;lt;Path&amp;gt; findResource(String relativeToWebContent) {
        return getWebContentFolder()
                .map(f -&amp;gt; f.getFile(relativeToWebContent))
                .map(f -&amp;gt; f.getLocationURI())
                .map(u -&amp;gt; Paths.get(u))
                .filter(p -&amp;gt; Files.exists(p));
    }

    private static Optional&amp;lt;IFolder&amp;gt; getWebContentFolder() {
        try {
            return Optional.ofNullable(SecurityManager
                    .getSecurityManager()
                        .executeAsSystem(() -&amp;gt; Ivy.request()
                                .getProcessModelVersion()
                                    .getProject().getFolder("webContent")));
        } catch (Exception failToGetWebContent) {
            throw new RuntimeException("Fail to reach webContent folder", failToGetWebContent);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">trungdv</dc:creator><pubDate>Thu, 27 Oct 2016 12:30:32 -0400</pubDate><guid>https://answers.axonivy.com/questions/2143/how-to-get-webcontent-folder-in-ivy-project/2145</guid></item></channel></rss>