0

I am using a configuration file into my software, i have the file in the correct root(non local) src/main/java/pdf/factory/fop.xconf. After compile the code, locally it looked for the file into fopBaseUri=C:\Users\user\Documents\software\local\target\data\bin\content\sftw.web-0.0.0-SNAPSHOT.war\WEB-INF\classes\pdf\fopfactorybasedir\fop.xconf

I didn't have that path, just had C:\Users\user\Documents\software\local\target\data\bin so i've created the rest of the path, and it worked like it should..

however, when i deployed, it didn't work, maybe becuase the path don't exist after compile, and it wipes it all when mvn install.

how can i force it to look into the path, or force the file to be the one i use ( non local into src/... )

heres my code:

@ApplicationScoped
public class FopFactoryService {
    private static final String ROOT_PATH = "/pdf/fopfactorybasedir/fop.xconf";
    private final FopFactory fopFactory;
    private final FOUserAgent foUserAgent;
    private final TransformerFactory transformerFactory;

    public FopFactoryService() throws URISyntaxException, IOException, SAXException {
        final URI uri = FopFactoryService.class.getResource(ROOT_PATH).toURI();
        final File f = new File(uri.getPath());
        LOG.info("fopBaseUri={}", f);
        fopFactory = FopFactory.newInstance(f);
        foUserAgent = fopFactory.newFOUserAgent();
        transformerFactory = TransformerFactory.newInstance();
    }

what am i missing?

Bruno
  • 404
  • 4
  • 16
  • Please share build error. – G.Chahar May 05 '20 at 12:01
  • it doesn't give any build error.. when i try to use the file, like printing the pdf, it justs go to the non-existing path, and (The system cannot find the specific file) – Bruno May 05 '20 at 12:16

1 Answers1

0

The file can be now located at the server after maven build.

The vfs path is internal, virtual file system Jboss creates for itself, but only inside memory used by jboss. The new File() looks on the real harddrive location. There is no such path, because it is only virtual there. That's a common problem since Jboss version 5, so the solution pass through this question answered here: Not getting absolute file path from resources if you get java.lang.ClassCastException: java.io.FileInputStream cannot be cast to org.jboss.vfs.VirtualFile just try that without cast. hope it help somebody.

Bruno
  • 404
  • 4
  • 16