compile java files inside jar

J

JR

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
 
R

Roedy Green

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
 
M

Mike Schilling

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?

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
 
J

JR

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
 
T

Tom Anderson

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
 
L

Lew

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>
 
O

Owen Jacobson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,725
Members
45,511
Latest member
Osiris-Team

Latest Threads

Top