Kubernetes - Docker Folder permission

6/25/2018

I have a docker image which is been deployed into kubernetes.

The docker file is as follows.

FROM alpine/jdk1.8:latest
RUN mkdir -p /opt/test/app
COPY app.war /opt/test/app/app.war

CMD java -jar /opt/test/app/app.war

This application uses hibernate and getting the below error when trying to load jar file for connection.

loggerName="org.hibernate.orm.url" threadName="main" txnId="" HHH10000002: File or directory named by URL [file:/opt/test/app/app.war!/WEB-INF/classes] could not be found.  URL will be ignored
java.io.FileNotFoundException: /opt/test/app/app.war!/WEB-INF/classes (No such file or directory)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:225)
    at java.util.zip.ZipFile.<init>(ZipFile.java:155)
    at java.util.jar.JarFile.<init>(JarFile.java:166)
    at java.util.jar.JarFile.<init>(JarFile.java:103)
    at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.resolveJarFileReference(JarFileBasedArchiveDescriptor.java:165)
    at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:51)
    at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:47)
    at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:75)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:199)
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)

Is there any permission to be given in docker file or in kubernetes deployment yaml file?

Hibernate config,

Map<String, String> Props = new HashMap<String, String>();
        conProps.put("javax.persistence.jdbc.url", "JDBC_URL");
        conProps.put("javax.persistence.jdbc.password", "PASSWORD");
        conProps.put("javax.persistence.jdbc.user", "USER");
        conProps.put("oracle.net.ssl_cipher_suites","CIPHER");
        conProps.put("javax.persistence.jdbc.driver", "oracle.jdbc.OracleDriver");

         Persistence.createEntityManagerFactory("appjdbc", conProps);

I checked the hibernate-core.jar and the below code gets executed. Not sure, if it is supposed to return JarProtocolArchiveDescriptor but returns JarFileBasedArchiveDescriptor.

public ArchiveDescriptor buildArchiveDescriptor(URL url, String entry) {
        final String protocol = url.getProtocol();
        if ( "jar".equals( protocol ) ) {
            return new JarProtocolArchiveDescriptor( this, url, entry );
        }
        else if ( StringHelper.isEmpty( protocol )
                || "file".equals( protocol )
                || "vfszip".equals( protocol )
                || "vfsfile".equals( protocol ) ) {
            final File file = new File( extractLocalFilePath( url ) );
            if ( file.isDirectory() ) {
                return new ExplodedArchiveDescriptor( this, url, entry );
            }
            else {
                return new JarFileBasedArchiveDescriptor( this, url, entry );
            }
        }
        else {
            //let's assume the url can return the jar as a zip stream
            return new JarInputStreamBasedArchiveDescriptor( this, url, entry );
        }
    }
-- user1578872
docker
kubernetes

1 Answer

6/26/2018

loggerName="org.hibernate.orm.url" threadName="main" txnId="" HHH10000002: File or directory named by URL [file:/opt/test/app/app.war!/WEB-INF/classes] could not be found. URL will be ignored

No, it's not a permission denied, it's using an incorrect URL scheme. file://thing is fine, but using the "bang" syntax requires prefixing the URL with jar:, like so:

jar:file:///opt/test/app/app.war!/WEB-INF/classes

Without more context I can't say whether that's a hibernate bug or a your-configuration bug, but I can say with high confidence that the error message is exactly correct: there is no such directory as app.war!

-- mdaniel
Source: StackOverflow