0

i am using grails 3.1.1 i already deployment my war file with tomcat 8 and i store all my image's file into /app/Item/

this is my folder's structure in my server.

/app/Item/<all my image>
/home
/root/apache-tomcat-8/
     /apache-tomcat-8/webapps
     /apache-tomcat-8/webapps/ROOT.war
     /apache-tomcat-8/bin
     /apache-tomcat-8/logs
     /apache-tomcat-8/work
     /apache-tomcat-8/temp
     /apache-tomcat-8/conf

now i am using symlink to access /app/Item so i create a symlink in /apache-tomcat-8/webapps/images with name images so when i access localhost:8080/images/100.JPG it will access to /app/Item/100.JPG

but i will get some error log if i rerun my tomcat, because folder images where i create with symlink isnot in my grails project. like this..

28-Feb-2017 12:43:44.962 WARNING [localhost-startStop-2] org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
 java.sql.SQLException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
  context: gambarku
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:283)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:718)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:650)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)

now i want to know how to access my folder /app/Item/ without symlink but from my grails application?

i tried to deploy without symlink or images's folder (shortcut)

    [root@li1447-147 bin]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd we
-bash: cd: we: No such file or directory
[root@li1447-147 apache-tomcat-8.5.8]# cd webapps/
[root@li1447-147 webapps]# rm -rf *
[root@li1447-147 webapps]# clear
[root@li1447-147 webapps]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd bin/
[root@li1447-147 bin]# ./startup.sh
Using CATALINA_BASE:   /root/apache-tomcat-8.5.8
Using CATALINA_HOME:   /root/apache-tomcat-8.5.8
Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.8/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_112
Using CLASSPATH:       /root/apache-tomcat-8.5.8/bin/bootstrap.jar:/root/apache-    tomcat-8.5.8/bin/tomcat-juli.jar
Tomcat started.
[root@li1447-147 bin]# tail -f ../logs/catalina.out
28-Feb-2017 16:13:06.353 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["http-nio-80"]
28-Feb-2017 16:13:06.368 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.370 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["https-jsse-nio-443"]
28-Feb-2017 16:13:06.613 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.613 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["ajp-nio-8009"]
28-Feb-2017 16:13:06.615 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.615 INFO [main] org.apache.catalina.startup.Catalina.load I    nitialization processed in 796 ms
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardService.st    artInternal Starting service Catalina
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardEngine.sta    rtInternal Starting Servlet Engine: Apache Tomcat/8.5.8
28-Feb-2017 16:13:06.657 INFO [localhost-startStop-1] org.apache.catalina.startu    p.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5    .8/webapps/ROOT.war
28-Feb-2017 16:13:13.193 INFO [localhost-startStop-1] org.apache.jasper.servlet.    TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs.     Enable debug logging for this logger for a complete list of JARs that were scan    ned but no TLDs were found in them. Skipping unneeded JARs during scanning can i    mprove startup time and JSP compilation time.

Configuring Spring Security Core ...
... finished configuring Spring Security Core

28-Feb-2017 16:13:49.628 INFO [localhost-startStop-1] org.apache.catalina.startu    p.HostConfig.deployWAR Deployment of web application archive /root/apache-tomcat    -8.5.8/webapps/ROOT.war has finished in 42,968 ms
28-Feb-2017 16:13:49.632 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [http-nio-80]
28-Feb-2017 16:13:49.638 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [https-jsse-nio-443]
28-Feb-2017 16:13:49.639 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [ajp-nio-8009]
28-Feb-2017 16:13:49.640 INFO [main] org.apache.catalina.startup.Catalina.start     Server startup in 43024 ms

------------------this is for symlink

then i tried to read this and add this code to my server.xml

<Context docBase="/app/Item" path="/gambarku" />

then startup.sh again.

i get this log.

28-Feb-2017 17:00:49.701 WARNING [localhost-startStop-1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
  context: gambarku
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

28-Feb-2017 17:00:49.772 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5.8/webapps/ROOT.war
28-Feb-2017 17:00:56.238 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

this log is same when i tried to use symlink.

i tried to find some documentation and i already check in folder WEB-INF/lib/mysql-connector-java-5.1.20.jar and build.gradle with runtime 'mysql:mysql-connector-java:5.1.20'

enter image description here

enter image description here

Community
  • 1
  • 1
  • The error is related a DB-Driver, not filesystem access! – Jens Feb 28 '17 at 12:58
  • @Jens yes, when running up my ROOT.war , the application will automatic create table base on my `domain-class`, that eror because, i don't have `domain-class` with name `images` –  Feb 28 '17 at 13:21
  • No the error is because the application can not load the Mysql- Driver: `Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java` – Jens Feb 28 '17 at 13:29
  • @Jens really? that erorr not show aftar i delete the `image`'s symlink :( –  Feb 28 '17 at 13:33
  • so you can restart tomcat without any issues after you delete the image folder? Can you try deploying/restart without adding the symlink or the image folder? – artemisian Feb 28 '17 at 14:39
  • @artemisian see my update question, i just try it. –  Feb 28 '17 at 16:17
  • when i receive this log `Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java`, my application still running and i can access from my domain/ip address –  Feb 28 '17 at 16:19
  • 1
    Please check this post: http://stackoverflow.com/questions/38268498/following-symbolic-link-in-grails-3 – artemisian Feb 28 '17 at 16:20
  • 1
    http://stackoverflow.com/questions/1812244/simplest-way-to-serve-static-data-from-outside-the-application-server-in-a-java http://stackoverflow.com/questions/417658/how-to-config-tomcat-to-serve-images-from-an-external-folder-outside-webapps and alternatively http://httpd.apache.org/docs/2.4/urlmapping.html – V H Feb 28 '17 at 16:27
  • @vahid i tried your suggestion link http://stackoverflow.com/questions/1812244/simplest-way-to-serve-static-data-from-outside-the-application-server-in-a-java –  Feb 28 '17 at 17:09
  • @artemisian see my update question –  Feb 28 '17 at 17:13
  • check my answer, hopefully it works. – artemisian Feb 28 '17 at 17:55

2 Answers2

0
def image = new File('/app/Item/image1.jpg')
Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22
0

This is a long shot but might solve your issue, it's very similar to the config you had originally, just adding allowLinking="true":

  • Create a symlink between /app/Item and /apache-tomcat-8/webapps/images
  • Add this to your configuration

          <Context docBase="/app/Item" path="/images" allowLinking="true"/>
    
artemisian
  • 2,976
  • 1
  • 22
  • 23
  • i must create symlink again? –  Mar 01 '17 at 03:28
  • i still get the same log.. 01-Mar-2017 03:31:55.091 WARNING [localhost-startStop-1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader context: gambarku delegate: false ----------> Parent Classloader: java.net.URLClassLoader@1fb3ebeb –  Mar 01 '17 at 03:32
  • Why it says gambarku, shouldn't say image? – artemisian Mar 01 '17 at 03:37
  • yes, i am change folder name so like this `Context docBase="/app/Item" path="/gambarku" allowLinking="true"/>` –  Mar 01 '17 at 03:39
  • Can you change it to image? Does the image folder exists in your webapps folder in your grails project? – artemisian Mar 01 '17 at 03:41
  • wait, must the `image`'s folder exist in webapps? –  Mar 01 '17 at 03:43
  • Doesn't hurt to add it. – artemisian Mar 01 '17 at 03:44
  • in `ROOT`'s folder or `webapps`? –  Mar 01 '17 at 03:44
  • In the webapps folder of your project. Not the ROOT – artemisian Mar 01 '17 at 03:45
  • No, not like that. In the webapp folder of the project source code. Then you need to create the war file again – artemisian Mar 01 '17 at 03:54
  • there's no `webapps` folder in my project, i am using grails, maybe you mean folder `assets` ? –  Mar 01 '17 at 03:56
  • Right assets is Grails 3 :) – artemisian Mar 01 '17 at 03:59
  • i already create folder `image` in folder assets then build war again..but i am thinking that i access file in `assets`'s folder with `localhost:8080/projectname/assets/100.JPG` but if i am setting `allowlinking` from `image` to `/app/Item` then what is the url of `/app/Item`? –  Mar 01 '17 at 04:05
  • when i create a blank's folder in `assets` and create a war file again, the grails will remove that's blank folder –  Mar 01 '17 at 04:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136918/discussion-between-artemisian-and-akiong). – artemisian Mar 01 '17 at 04:11
  • let's go to the chat room http://chat.stackoverflow.com/rooms/136918/discussion-between-artemisian-and-akiong – artemisian Mar 01 '17 at 04:13