troubleshooting Question

Java Singlton web file path

Avatar of wsyy
wsyy asked on
JavaWeb Development
41 Comments2 Solutions450 ViewsLast Modified:
Hi,

My web application needs to call a java class, which is a singlton and load files as inputs.

The structure is as follow:

ProjectName
    src/...../YYTLinearClassifier.java
    training/test.txt
    WebContent/index.jsp

The Test.java file is a singlton, and called by the index.jsp file.

During the initialization of the instance of the Test.java, the initialization will load the test.txt (under the training folder). Part of the .java file is attached.

I used a number of way to load the .txt, but failed to do so.

Does anyone have the same experience?

Thanks


public class YYTLinearClassifier extends ColumnDataClassifier {

	private static Classifier<String, String> cdc;

	private static boolean serialized = true;

	private static final String modelPath = "/training/model/yytmodel.ser";
	private static final String propPath = "/training/yytmodel.prop";
	private static final String trainPath = "/training/yytmodel.train";

	private static YYTLinearClassifier instance;

	public static YYTLinearClassifier getInstance() {
		if (instance == null) {
			Properties props = StringUtils.propFileToProperties(propPath);
			instance = new YYTLinearClassifier(props);

			if (!serialized) {
				cdc = instance.makeClassifier(instance
						.readTrainingExamples(trainPath));
				serialized = serializeClassifier(cdc);

			} else if (!deserializeClassifier()) {
				instance = null;
			}
		}

		return instance;
	}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 41 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 41 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros