简体   繁体   中英

Java code not working in OSX Mavericks

I'm trying to run a java library, so that I can build upon it and do my customization. The library is called jayu parses ASN files so that you can decode them. It can be downloaded here

There are a few test data to check the library in the "test" folder and mentioned in the Readme.txt file. There is a asn2csv batch file for windows but I'm using OSX mavericks. According to the Readme file, I need to run it by invoking the command:

ls $ASN_DATA_DIR/*.dat | xargs java -cp "./*.jar:."  Path/To/Stream1.txt  test.testdata.Stream1 $OUTPUT_DIR

OR

java -cp "*.jar;$PATH_TO_TEST_DIR" Stream1.txt test.testdata.Stream1  . Path/To/Stream1.dat

But whatever I try I always get Error: Could not find or load main class Stream1.txt

I'm not a Java programmer. What am I doing wrong here? The development of this seems to be inactive lately but it's still useful. So, I'm posting it here, hoping someone will help me run the example.

Edit: I've added the tree structure of the directory and the files

+ jayu
     |--Readme.txt           
     |--commons-compiler.jar
     |--janino.jar
     |--jayu.jar             (ASN parser)
     |--AsnToCsv.bat         (Command line Tool)
     +--test                 (Contains test data for examples)
         |
         + testdata         
              |
              Stream1.txt   (Grammar File)
              Stream1.dat   (ASN Data File)
              Stream1.java  {mapFile}
              ...

It is interpreting Stream1.txt as the Java class you are trying to execute, because it is treating at as your first argument to java . Your first argument should be the name of the class containing the main() , or, the executable JAR must be indicated with a -jar option.

This would seem to indicate that "*.jar;$PATH_TO_TEST_DIR" is evaluating to blank. Can you see if there are any .jar files in your current working directory? Also what is the value of $PATH_TO_TEST_DIR ?

Another thing is that if you use the second form on OS X, you should have a : instead of a ; because it is a Unix-based OS, not Windows.


Update1

I had a slight error with my description of how to run an executable JAR. You use the -jar option, not -cp (I corrected it above). Since they put -cp in their invocation, I'm guessing they are not intending to target the executable JAR, but rather to name the main class. That to me says that test.testdata.Stream1 is that main class, which means the ordering they gave you is wrong. Try this:

java -cp "*.jar:$PATH_TO_TEST_DIR" test.testdata.Stream1 Stream1.txt . Path/To/Stream1.dat

or some other ordering that starts with:

java -cp "*.jar:$PATH_TO_TEST_DIR" test.testdata.Stream1 ..........

That is, that makes test.testdata.Stream1 the very first command line argument to java .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM