1

There is a java program in the folder

Downloads/jason/src/demo/de/l3s/jason/testfile.java

I can compile it with javac testfile.java (while in that directory) Resulting in testfile.class.

But I cannot run this file by typing java testfile If I manage to run the file, it cannot locate any components of the file.

The testfile.java contains

 package de.l3s.jason.demo;

 import java.net.URL;

 import de.l3s.jason.extractors.ArticleExtractor;

 public class testfile 

And then a couple of lines of code.

How do I tell Java where to look for these components?

I have added several jar files to the classpath (per the documentation) by copying them directly into home/usr/lib/jvm/java/jre/lib/ext

Aside from that, the classpath works fine with "java" and "javac" working from anywhere.

I couldn't get this to work on Windows either, which is why I switched to linux.

4 Answers 4

2

try

java de.l3s.jason.demo.testfile

But first make sure it contains a

public static void main (String [] args);
Sign up to request clarification or add additional context in comments.

1 Comment

The command works in the src folder. It executes the program.
2

Try:

java de.l3s.jason.demo.testfile

Comments

2

Please try java de.l3s.jason.demo.testfile. Maybe you need to add more jar-Files to the classpath then that, so please enter the result here.

Comments

2

Assuming you have compiled all classes within the source tred and the compiled classfiles are stored in the directory where your .java file is, then you need to use the following command.

java -cp Downloads/jason/src/demo de.l3s.jason.testfile

Note the usage of the -cp switch to specify the classpath's root directory (where the package structure starts)

If the classes need additional libraries, you need to include them in the -cp switch:

java -cp Downloads/jason/src/demo:/some/dir/somelib.jar:/other/dir/otherlib.jar  de.l3s.jason.testfile

(Assuming you are on a Unix style operating system. On Windows you need to use ; as the path separator and of course a backslash instead of a forward slash)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.