我正在使用grails 3.1.1
我已经使用tomcat 8部署了war文件,并将我的所有图像文件存储到/app/Item/
这是我服务器中的文件夹结构。
/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
现在我使用symlink
访问/app/Item
所以我在/apache-tomcat-8/webapps/images
创建了一个名为images
的符号链接
因此,当我访问localhost:8080/images/100.JPG
时,它将访问/app/Item/100.JPG
但是如果我重新运行我的tomcat,我会得到一些错误日志,因为我用images
创建的文件夹symlink
不在我的grails项目中。
喜欢这个..
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)
/app/Item/
但我的grails应用程序中访问我的文件夹symlink
?我尝试在没有symlink
或images
的文件夹(快捷方式)的情况下进行部署
[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
------------------这是symlink
然后我尝试read this并将此代码添加到我的server.xml
<Context docBase="/app/Item" path="/gambarku" />
然后再次启动。
我得到这个日志。
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.
当我尝试使用symlink
时,此日志相同。
我试图找到一些文档,我已经在文件夹WEB-INF/lib/mysql-connector-java-5.1.20.jar
和build.gradle中检查runtime 'mysql:mysql-connector-java:5.1.20'
答案 0 :(得分:0)
def image = new File('/app/Item/image1.jpg')
答案 1 :(得分:0)
这是一个很长的镜头,但可能会解决您的问题,它与您最初的配置非常相似,只需添加 allowLinking =“true”:
将此添加到您的配置
<Context docBase="/app/Item" path="/images" allowLinking="true"/>