Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2372 > unrolled thread

how to compile open source classes

Started byadamchapman1985@hotmail.co.uk
First post2012-12-20 02:52 -0800
Last post2012-12-20 10:59 -0800
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.help


Contents

  how to compile open source classes adamchapman1985@hotmail.co.uk - 2012-12-20 02:52 -0800
    Re: how to compile open source classes "John B. Matthews" <nospam@nospam.invalid> - 2012-12-20 09:10 -0500
      Re: how to compile open source classes Lew <lewbloch@gmail.com> - 2012-12-20 10:59 -0800

#2372 — how to compile open source classes

Fromadamchapman1985@hotmail.co.uk
Date2012-12-20 02:52 -0800
Subjecthow to compile open source classes
Message-ID<e00601f3-4a26-427b-aefe-2a860e0eec9b@googlegroups.com>
Hi, I have downloaded an open source library containing .java and .class files.

I'm a complete java novice but all I want to do is compile this library into a .jar file, so I can effectively call it from a command line, as I have done before at http://undocumentedmatlab.com/blog/jboost-integrating-an-external-java-library-in-matlab/

If anyone can tell me what to do in order to build a .jar file I'd be very grateful.

[toc] | [next] | [standalone]


#2373

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-12-20 09:10 -0500
Message-ID<nospam-FEDE9B.09105020122012@news.aioe.org>
In reply to#2372
In article <e00601f3-4a26-427b-aefe-2a860e0eec9b@googlegroups.com>,
 adamchapman1985@hotmail.co.uk wrote:

> Hi, I have downloaded an open source library containing .java and 
> .class files.
> 
> I'm a complete java novice but all I want to do is compile this 
> library into a .jar file, so I can effectively call it from a command 
> line, as I have done before at 
> http://undocumentedmatlab.com/blog/jboost-integrating-an-external-java-library-in-matlab/
> 
> If anyone can tell me what to do in order to build a .jar file I'd be 
> very grateful.

As you are using an open source library, why not simply link to the 
project? If it doesn't already contain a JAR or documented build target, 
you might want to start with the tutorial:

<http://docs.oracle.com/javase/tutorial/deployment/jar/>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#2374

FromLew <lewbloch@gmail.com>
Date2012-12-20 10:59 -0800
Message-ID<a804e6d1-738a-4288-8ea0-640bfcbdac52@googlegroups.com>
In reply to#2373
John B. Matthews wrote:
>adamchapman1985 wrote:
>> Hi, I have downloaded an open source library containing .java and 
>> .class files.
> 
>> I'm a complete java [sic] novice but all I want to do is compile this 
>> library into a .jar file, so I can effectively call it from a command 

Compile and jar are two separate steps.

>> line, as I have done before at 
>> http://undocumentedmatlab.com/blog/jboost-integrating-an-external-java-library-in-matlab/

I do not know MatLab, but assuming it just uses standard JARs I can offer some suggestions.

>> If anyone can tell me what to do in order to build a .jar file I'd be 
>> very grateful.
> 
> As you are using an open source library, why not simply link to the 
> project? If it doesn't already contain a JAR or documented build target, 
> you might want to start with the tutorial:
> 
> <http://docs.oracle.com/javase/tutorial/deployment/jar/>

What he said, but allow me to summarize. Suppose you don't want to use their JAR, but
you really want to do just what you said - create your own JAR.

There are three steps you asked for:
"compile this library into a .jar file, so I can effectively call it from a command line"
- Compile
- Jar
- Execute

In command-line terms (bravo to you!) these commands are:
- javac
   http://docs.oracle.com/javase/7/docs/technotes/guides/javac/index.html
- jar
   http://docs.oracle.com/javase/7/docs/technotes/guides/jar/index.html
- java
   http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
   http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html

all of which can be controlled via Ant.

javac: .java => .class
jar:    .class => .jar
java:  {.class, .jar} => magic

All these are documented! Isn't that incredible?
http://docs.oracle.com/javase/7/docs/index.html

Now, if you trust the .class files you get from Joe Opensource, you have no need to 
compile the .java files.

If you compile the .java files, you have no need for the .class files.

So choose one of two steps to get a bunch of .class files:
- Use the downloaded .class files, or
- Compile your own.

Don't mix and match.

So now you have a set of .class files. Let's pretend that they're in the standard directory-
based layout for Java .class files, rooted at classpath element **/opensource/build/, and that
the packages all start at org.opensource.magic.

.../opensource/build/org/opensource/magic/Foo.class
.../opensource/build/org/opensource/magic/util/Util.class

and so on.

Now you want to JAR them. I'll assume you "cd" into ".../opensource/". There are a few ways to 
build the JAR.

$ jar cmf path/to/myManifestFile opensource.jar -C build .

That manifest file has to specify the main class or you won't be able to run the JAR from the 
command line.

Alternatively, you can use the jar "-e" option to specify the main class.

You also have to set the "Class-Path:" in the manifest, or you will not be able to run the JAR 
file if it needs certain things in its classpath that are not already in the JAR. Running from a 
JAR file forces the "java" command to ignore all other classpath information.

To run that JAR file use "java -jar opensource.jar".

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web