Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Compilation tips  RSS feed

 
Eugenio Raul
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
A friend of mine has written a class let's say com.myfriend.classA.class
This class belongs to a web application : myfriend.war
In MY web application, I need to use this class.
com.myfriend.classA.getXXX();
To be able to compile my webApp, I need a reference to his class.
The compiler raises an error if classA is not in my path.
Is there a mean to bypass this or do I need to ask my friend for a jar file include in my path.
Thanks in advance.
By the way, I know this question is stupid
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, this question is NOT stupid. Really now, you shouldn't make the rest of us, who don't know the answer to this question either, feel bad .
So the question is - can the JVM read a .war file just like a .jar file, or not?
I am going to move this over to the J2EE forum and see if those folks know the answer to this question.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Theree are three things you can do:
(1) Put the class alone one your classpath or add the root directory that contains the "com" directory the class is in to your classpath.
(2) Ask your friend to make a jar and add it to the classpath
(3) Use your friend's WAR and add that to your classpath.

Any of the above will work for compilation.
Kyle
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given what you CAN do, it's a good idea to consider what you SHOULD do - which in the real world is often pre-empted by what you MUST do (which is to get the #$%#%! thing working).
If your friend's code is of general interest, he/she (or you) should consider breaking it out into a utility jar file distinct from the webapp. You can then place it in a commonly-accessible location and share it on an equal basis.
If the code is dependent on the context of the friend webapp, it's a good idea to make a formal interface of it in the friend app rather than simply call in. Otherwise changes in the friend app can cause your app to misbehave later when the friend app gets updated or you tweak your own app and forget that there are external issues.
Ideology is for idiots, BTW. Uncountable atrocities have come from taking a good idea and attempting to use it as the universal solution. However, the mark of a good idea is that it works. The mark of wisdom is knowing the point beyond which a good idea no longer works.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
Theree are three things you can do:
(3) Use your friend's WAR and add that to your classpath.

Any of the above will work for compilation.
Kyle


Kyle,
The classes contained in a war file are like :
WEB-INF/CLASSES/com/xxx/xxx
While in a jar file the /WEB-INF/CLASSES/ part does not exist
So I don't understand how the compiler can resolve a reference to a class when it is contained in a war file.
According to me, he looks for com.xxx.xxx and only find WEB-INF.CLASSES.com.xxx.xxx and
Please explain
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!