Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The following script works on Ubuntu, but not on Mac. Why? How to edit it so that it would work there too?

#!/bin/sh

v=1.1
test_file="Test10.java"
jar_file="dp4j-$v-jar-with-dependencies.jar"

curl -O "http://repo2.maven.org/maven2/com/dp4j/dp4j/$v/$jar_file"

# Start
cat > $test_file << __EOF__
class T10 {
    private static void p(int i, Double d, String... s){}
}
public class Test10{
    @com.dp4j.InjectReflection
    public void t() {
   T10.p(1,new Double(2),"hello", "reflection");
    }
}
__EOF__
cat $test_file
cmd="javac -Averbose=true -cp $jar_file $test_file"
echo $cmd
$cmd

The output on the mac:

$ sudo ./TESTDRIVE
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  341k  100  341k    0     0  1516k      0 --:--:-- --:--:-- --:--:-- 3248k
class T10 {
    private static void p(int i, Double d, String... s){}
}
public class Test10{
    @com.dp4j.InjectReflection
    public void t() {
  T10.p(1,new Double(2),"hello", "reflection");
    }
}
javac -Averbose=true -cp dp4j-1.1-jar-with-dependencies.jar Test10.java
error: error reading dp4j-1.1-jar-with-dependencies.jar; cannot read zip file
...

$ md5 dp4j-1.1-jar-with-dependencies.jar MD5 (dp4j-1.1-jar-with-dependencies.jar) = eb04d0d357fd861ac414fde7d3530119

share|improve this question

migrated from stackoverflow.com Mar 4 '11 at 15:52

This question came from our site for professional and enthusiast programmers.

    
Try using curl --fail -O ... instead. This will cause curl to fail completely if it receives an HTTP error instead of writing the error text to the output file. –  D.Shawley Mar 1 '11 at 18:16
    
It doesn't fail. $ curl --fail -O repo2.maven.org/maven2/com/dp4j/dp4j/1.1/… % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 341k 100 341k 0 0 576k 0 --:--:-- --:--:-- --:--:-- 739k –  simpatico Mar 1 '11 at 21:28

2 Answers 2

Have you checked if you're actually getting a .jar file?. Many download links do a silent redirect to where the file actually is, so you might be downloading only a few bytes with a Location: ... redirect which CURL isn't following.

Open up the .jar file in a text editor and see what you've got. A real .jar should start with 'PK' (since it's a .zip file).

share|improve this answer
    
tried that..It's not the issue (it works on linux). The jar is indeed downloaded, but corrupt. –  simpatico Mar 1 '11 at 18:09
    
Open the jar in a text editor or hexdump it. For some reason I was receiving an HTML file with a 404 message occasionally under both Windows and on my MacBook. If the server responds with a 404 status and an error page, then curl will gladly write the error page out as a file for you. –  D.Shawley Mar 1 '11 at 18:13
    
i did all that..it's full of byte code (I already had the problem you guys refer to =) ) –  simpatico Mar 1 '11 at 18:22
    
Run it through a zip repairer. See if it's still even remotely a zip file internally. winzip/7zip would do. the CLI zip for Linux has a repair option as well, but I can't remember what the arg is to invoke it. –  Marc B Mar 1 '11 at 18:30
up vote 0 down vote accepted

curl -L

works. It even follows redirects. I found this out in this answer. Refer to working script.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.