Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Java Questions
Java Questions [message #1174446] Thu, 07 November 2013 05:17 Go to next message
Arnav Kumar is currently offline Arnav Kumar
Messages: 16
Registered: October 2013
Junior Member
Java Questions for java beginners
TechknowHeights


[Updated on: Thu, 07 November 2013 05:18]

Report message to a moderator

Re: Java Questions [message #1177154 is a reply to message #1174446] Fri, 08 November 2013 20:18 Go to previous messageGo to next message
John Mising name is currently offline John Mising name
Messages: 11
Registered: July 2011
Junior Member
For several years, I've built a project and run it using simple batch file when I'm not in Eclipse, as follows:
"c:\program files\Java\jdk1.6.0_18\bin\javac" srcdir\*.java
"c:\program files\Java\jdk1.6.0_18\bin\java" srcdir/packagename
And there is the appropriate package statement in the main class's .java definition.
pause

The above batch file works fine. The program compiles and runs no problem. The program depends on lots
of Java .jar files. They are found no problem.

Here's my problem: Someone recently split the project up into just a small number of .jar files, including
one for the main program. But if I type something like java -jar packagename.jar, the program will no longer
find some of the same Java .jar files (even though it has the same dependencies on them). Does anyone know
why it's so much easier for the java command to find dependent .jar files so easily if the main class is
in a .class file but it's much harder when the main class is now in a .jar file? When I execute a .class file,
I have no problem. But now that someone put the class in a .jar file, it no longer finds the other jars.
Admittedly, I'm using a later version of the Java JDK but that shouldn't matter. The person uses an
XML script as a manifest but I can read the dependencies in that script and I see what he's doing but
I don't want to run it over the Internet when I have the .jar files locally. How can I take a .jar
file that's the main class and simply list the other jars? MUST I create a manifest or can I simply
list them somehow on the command line of the java.exe command. I'm pretty much clueless but I know
if I list them somehow that the program will NOT get java.lang.NoClassDefFoundError which is what
it gets now. I'm not real worried about this, I'd just like to understand something that would
seem to me to be pretty simple. Why does creating a .jar file upset the whole process so much?
Should it upset the process so much?
Re: Java Questions [message #1177349 is a reply to message #1177154] Fri, 08 November 2013 23:25 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1344
Registered: July 2009
Senior Member
On 11/8/2013 2:18 PM, John Mising name wrote:
> For several years, I've built a project and run it using simple batch
> file when I'm not in Eclipse, as follows:
> "c:\program files\Java\jdk1.6.0_18\bin\javac" srcdir\*.java
> "c:\program files\Java\jdk1.6.0_18\bin\java" srcdir/packagename
> And there is the appropriate package statement in the main class's .java
> definition.
> pause
>
> The above batch file works fine. The program compiles and runs no
> problem. The program depends on lots
> of Java .jar files. They are found no problem.
>
> Here's my problem: Someone recently split the project up into just a
> small number of .jar files, including
> one for the main program. But if I type something like java -jar
> packagename.jar, the program will no longer
> find some of the same Java .jar files (even though it has the same
> dependencies on them). Does anyone know
> why it's so much easier for the java command to find dependent .jar
> files so easily if the main class is
> in a .class file but it's much harder when the main class is now in a
> .jar file? When I execute a .class file, I have no problem. But now
> that someone put the class in a .jar file, it no longer finds the other
> jars.
> Admittedly, I'm using a later version of the Java JDK but that shouldn't
> matter. The person uses an
> XML script as a manifest but I can read the dependencies in that script
> and I see what he's doing but
> I don't want to run it over the Internet when I have the .jar files
> locally. How can I take a .jar
> file that's the main class and simply list the other jars? MUST I
> create a manifest or can I simply
> list them somehow on the command line of the java.exe command. I'm
> pretty much clueless but I know
> if I list them somehow that the program will NOT get
> java.lang.NoClassDefFoundError which is what
> it gets now. I'm not real worried about this, I'd just like to
> understand something that would
> seem to me to be pretty simple. Why does creating a .jar file upset the
> whole process so much?
> Should it upset the process so much?

Running an application using java -jar is quite different from running a
..class file with respect to the classpath used.

I suggest that you go through the Oracle tutorial for packaging programs
in jars.

http://docs.oracle.com/javase/tutorial/deployment/jar/index.html
Re: Java Questions [message #1190484 is a reply to message #1177349] Sat, 16 November 2013 16:29 Go to previous message
John Mising name is currently offline John Mising name
Messages: 11
Registered: July 2011
Junior Member
The main jre/lib/ext directory is a good spot to put my extra jars such as 3D lib jars. But, I would rather not take copies of my 3D libs and put them there (from their original install directory under 1.5.2 dir). What should I say on the command-line to replace this - something like -jar pathtojar/thelib.jar? or just the thelib or something?

I would rather leave my 3D jars in their original directories. This is not a big deal as my programs compile and run fine but as you say, the tutorial would help.

Also, I normally use the command-line to build my java projects but sometimes I DO use Eclipse - particularly when I have a lot of debugging. Is there a way I can get at the internal command that is synthesized by Eclipse to do the build? I would learn more if I knew where that command was kept?

I did not find the tutorial much help. I just want a simple explanation of what to say on the command-line. I am not looking for a way to package things. My program compiles and runs fine - but I have to copy the 3D jars to the jre/lib/ext directory - I just want to know what to add to the command-line to reference this jar during a build by the javac command so that I don't have to copy my 3D jars (the 3 or 4 of them) to that directory. Do I just say -jar and then a "well-formed" path to the jars? Perhaps I need to list each jar individually.

Here's all the flags for javac:
>javac -help
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system

Should I use the -extdirs or -endorsedirs? I would think that -classpath, -cp, and
-sourcepath would not help since I'm only talking about jars.

Should I override the installed extensions and just copy everything to a new more
centralized directory? By everything, I mean stuff like rt.jar and so forth. I don't know how many I need to copy - I may need to get at the dependencies using some command.

Any help appreciated.
Thank you. Razz

[Updated on: Sat, 16 November 2013 16:42]

Report message to a moderator

Previous Topic:Writing JAR from plug-in (not from File menu)
Next Topic:Create IJavaProject in non ui test
Goto Forum:
  


Current Time: Thu Oct 23 17:28:39 GMT 2014

Powered by FUDForum. Page generated in 0.02441 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software