compile java files inside jar

Discussion in 'Java' started by JR, Jan 14, 2010.

  1. JR

    JR Guest

    I have a jar file with a number of .java files in it. The file is
    called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar. I would like to
    compile all the files in it into class files and save them all into a
    file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    directory structure in the sources.jar file. Any idea how to do this
    or how to modify my ant script to do this when compiling thru eclipse?

    Thanks.

    JR
    JR, Jan 14, 2010
    #1
    1. Advertising

  2. JR

    Roedy Green Guest

    On Thu, 14 Jan 2010 13:47:56 -0800 (PST), JR <>
    wrote, quoted or indirectly quoted someone who said :

    >I have a jar file with a number of .java files in it. The file is
    >called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar. I would like to
    >compile all the files in it into class files and save them all into a
    >file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    >directory structure in the sources.jar file. Any idea how to do this
    >or how to modify my ant script to do this when compiling thru eclipse?


    see http://mindprod.com/jgloss/onthefly.html

    http://mindprod.com/jgloss/javacompiler.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    I decry the current tendency to seek patents on algorithms. There are better ways to earn a living than to prevent other people from making use of one’s contributions to computer science.
    ~ Donald Ervin Knuth (born: 1938-01-10 age: 72)
    Roedy Green, Jan 14, 2010
    #2
    1. Advertising

  3. JR wrote:
    > I have a jar file with a number of .java files in it. The file is
    > called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar. I would like to
    > compile all the files in it into class files and save them all into a
    > file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    > directory structure in the sources.jar file. Any idea how to do this
    > or how to modify my ant script to do this when compiling thru eclipse?


    1. Explode the jar file into the filesystem.
    2. Do your build
    3. Jar up the result

    Ant can automate all of this for you.

    1. The unjar task
    2. The javac task
    3. The jar task
    Mike Schilling, Jan 14, 2010
    #3
  4. JR

    JR Guest

    On Jan 14, 3:58 pm, "Mike Schilling" <>
    wrote:
    > JR wrote:
    > > I have a jar file with a number of .java files in it.  The file is
    > > called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar.  I would like to
    > > compile all the files in it into class files and save them all into a
    > > file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    > > directory structure in the sources.jar file.  Any idea how to do this
    > > or how to modify my ant script to do this when compiling thru eclipse?

    >
    > 1. Explode the jar file into the filesystem.
    > 2. Do your build
    > 3. Jar up the result
    >
    > Ant can automate all of this for you.
    >
    > 1. The unjar task
    > 2. The javac task
    > 3. The jar task


    Thanks for the reply. What you say sounds exactly what I'm trying to
    do. How would you do this based on the name of my jar files above if
    you don't mind helping me out. I'm not overly familiar with creating
    ant scripts right now.

    Thanks.

    JR
    JR, Jan 14, 2010
    #4
  5. JR

    Tom Anderson Guest

    On Thu, 14 Jan 2010, JR wrote:

    > I have a jar file with a number of .java files in it. The file is
    > called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar. I would like to
    > compile all the files in it into class files and save them all into a
    > file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    > directory structure in the sources.jar file. Any idea how to do this


    Shell script to run from in the same directory as the jar:

    rm -rf src classes
    mkdir src classes
    cd src
    jar xf ../spring-surf-1.0.0.CI-SNAPSHOT-sources.jar
    find . -name \*.java | xargs javac -d ../classes
    cd ../classes
    jar cf ../spring-surf-1.0.0.CI-SNAPSHOT.jar *
    cd ..
    rm -r src classes

    Note that if the code depends on any other libraries, you'll need to
    add them to the classpath of the javac command.

    > or how to modify my ant script to do this when compiling thru eclipse?


    Translate the above shell script into ant. Consult the ant manual for more
    on how to do this!

    tom

    --
    .... the full attack expands into an unusual pseudosteganographic
    strikeback methodology against peer to peer networks. -- Dan Kaminsky
    Tom Anderson, Jan 14, 2010
    #5
  6. JR

    Lew Guest

    JR wrote:
    >>> I have a jar file with a number of .java files in it.  The file is
    >>> called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar.  I would like to
    >>> compile all the files in it into class files and save them all into a
    >>> file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    >>> directory structure in the sources.jar file.  Any idea how to do this
    >>> or how to modify my ant script to do this when compiling thru eclipse?

    >


    Mike Schilling wrote:
    >> 1. Explode the jar file into the filesystem.
    >> 2. Do your build
    >> 3. Jar up the result
    >>
    >> Ant can automate all of this for you.
    >>
    >> 1. The unjar task
    >> 2. The javac task
    >> 3. The jar task

    >


    JR wrote:
    > Thanks for the reply.  What you say sounds exactly what I'm trying to
    > do.  How would you do this based on the name of my jar files above if
    > you don't mind helping me out.  I'm not overly familiar with creating
    > ant scripts right now.
    >


    jar xf sources.jar -C sourcedir
    cd sourcedir
    javac -d destinationdir path/to/Main.java
    cd destinationdir
    jar cf binaryjar *

    Have you thought at all about reading the documentation? It's a
    really good idea and often surprisingly helpful. You should try it.

    <http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html>
    <http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html>
    <http://ant.apache.org/manual/index.html>

    --
    Lew
    Lew, Jan 14, 2010
    #6
  7. On 2010-01-14 16:47:56 -0500, JR <> said:

    > I have a jar file with a number of .java files in it. The file is
    > called spring-surf-1.0.0.CI-SNAPSHOT-sources.jar. I would like to
    > compile all the files in it into class files and save them all into a
    > file called spring-surf-1.0.0.CI-SNAPSHOT.jar retaining the existing
    > directory structure in the sources.jar file. Any idea how to do this
    > or how to modify my ant script to do this when compiling thru eclipse?
    >
    > Thanks.
    >
    > JR


    You can always check out the Surf source tree directly (from
    https://anonsvn.springframework.org/svn/se-surf/trunk/ -- found on
    http://www.springsource.org/extensions/se-surf) and build it. It looks
    like their build uses maven, rather than ant, so 'mvn package' from the
    root of the surf source tree will give you compiled JARs.

    Normally you'd be able to download binaries yourself, but it looks like
    the maven repositories the Surf project publishes to are offline. Keep
    an eye on https://extensions.springframework.org/snapshot and
    https://extensions.springframework.org/milestone as well as the surf
    site.

    (The -sources.jar file you have likely came out of one of their nightly
    builds. If you know where you got it, there should be a binary JAR in
    the same place.)

    -o
    Owen Jacobson, Jan 14, 2010
    #7
  8. JR

    Roedy Green Guest

    On Thu, 14 Jan 2010 13:55:26 -0800, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    >
    >see http://mindprod.com/jgloss/onthefly.html
    >
    >http://mindprod.com/jgloss/javacompiler.html


    With this technique you unpack each *.java file into RAM, then compile
    it. You don't need to create/delete any *.java files on the file
    system. You will still have to collect up the resulting *.class files
    into a jar.

    http://mindprod.com/jgloss/jar.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    I decry the current tendency to seek patents on algorithms. There are better ways to earn a living than to prevent other people from making use of one’s contributions to computer science.
    ~ Donald Ervin Knuth (born: 1938-01-10 age: 72)
    Roedy Green, Jan 15, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. harry
    Replies:
    1
    Views:
    483
    Sudsy
    Nov 22, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    567
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,718
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,752
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    657
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page