0

I am deploying a WAR file in Tomcat for a webapp (my first time doing this) that I've developed. The problem comes when I deploy the app and the resources can't be found.

I am saving the files (for example a CSV file) in this foulder of the project:

"src/main/resources/diseases.csv"

And when I deploy the project in tomcat, tomcat give me this error:

"org.apache.spark.sql.AnalysisException: Path does not exist: file:/opt/tomcat/apache-tomcat-9.0.16/bin/src/main/resources/conenfermedad.csv;"

This is the line of the code where I am having the error:

String dataPred = thalg.randtrp("src/main/resources/conenfermedad.csv",             
                "src/main/resources/outWekaEnfermedad.arff");

EDIT: I have been trying differents solutions but I have the same problem because if I use InputStream how can I get the path to use a dataFrameReader (this only use path as String)?

InputStream is = getClass().getResourceAsStream(In);

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        //InputStream is = getClass().getResourceAsStream(In);

        final DataFrameReader dataFrameReader = sparkSession.read().option("header", true);
        final Dataset<Row> trainingData = dataFrameReader.csv(In).toDF("IDPatient", "ECG_EKG", "Temp",
                "SPO2Min", "SPO2Max", "BPMmin", "BPMmax", "BPMavg", "SYS", "DIA", "EDAmin", "EDAmax", "EDAavg", "Disease");
        // con "*.csv" para que lea todo el directorio

What should am I doing wrong?

Thanks in advance :)

JCJunior
  • 29
  • 5
  • Possible duplicate of [Reading a resource file from within jar](https://stackoverflow.com/questions/20389255/reading-a-resource-file-from-within-jar) – Pino Mar 21 '19 at 09:19

1 Answers1

0

Make sure your CSV-file is included in your WAR-file. Since a WAR-file is technically just a ZIP-file you can use any ZIP-program to check this.

If you are using Maven you need to explicitly include it:

<build>
...
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
            <includes>
                <include>diseases.csv</include>
            </includes>
        </resource>
    </resources>
...
</build>

Filtering can be set to false (or left out) if you don't need any replacement of placeholders. In the include tag you can also use wildcards.

And then you can use the csv file like this:

new InputStreamReader(getClass().getResourceAsStream("/diseases.csv"), StandardCharsets.UTF_8.name())
Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
  • Using getResourceAsStream is exactly what is suggested by answers in https://stackoverflow.com/questions/20389255/reading-a-resource-file-from-within-jar A duplicate question doesn't deserve a duplicate answer, – Pino Mar 21 '19 at 10:19
  • @Pino Since OP already uses getResourceAsStream in his edit something else is wrong and my guess is that the file is not included in the WAR. – Joachim Rohde Mar 21 '19 at 10:27
  • Yes, now I have seen the edit, but it's not clear how OP is using the result of getResourceAsStream(). Perhaps he should read better the examples already available in that post. – Pino Mar 21 '19 at 10:35