File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Yikes - Java .ear .jar .class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Yikes - Java .ear .jar .class " Watch "Yikes - Java .ear .jar .class " New topic
Author

Yikes - Java .ear .jar .class

Rich Bantges
Greenhorn

Joined: Jul 17, 2012
Posts: 4
Hi there,

This is probably going to be the stupidest question on here, but I'm trying to find out the answer to the following:
I have an enterprise application package (let's called it mywebsite.ear) that contains source for a website that is run on Sun's Java Application Server (running on SOLARIS 10 SPARC).
The package contains serveral .jar packages (with associated META-INF and website-related directories).

I've also got access to the original source code.

All I'd like to do is edit one of the .java files that makes up one of the .jar packages (let's call it read.jar), and the java file read_source.java

Is there a simple way of editing the .java file and then recompiling the .jar file to drop in to the appropriate part of the webserver?
I've tried editing the .java file, compiling it and restarting the webserver (Java Application Server) but it doesn't work.

I'm wondering if I need to start from scratch with the source?

Thanks and sorry I've probably omitted lots of important information that's required to help..

Rich
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
You should change the source files which should not be part of the .jar files. You need to make sure you have the last versions of the sources that were last deployed (a tag in SVN terms) and modify a copy of that last known set of source files.
Now would be a good time to read up on source code control tools and build/deploy strategies so that your solution makes it easier to do these changes again next time changes are required.
Rich Bantges
Greenhorn

Joined: Jul 17, 2012
Posts: 4
Thanks for the quick reponse. I've edited the source files, and I'm running Netbeans on Windows 7. Is there a way I can just compile the read.jar file and drop it back into the SUNWappserver domain?

So, I think my questions are:
1. Can I compile a .jar file on Windows 7 so that it will be compatible with the Java installed on the SOLARIS SPARC system, or must I compile the .jar on the SOLARIS system itself?
2. Once I've compiled the read.jar file, can I just put this file into the SUNWappserver/domain (where the current read.jar files resides) or do I need to put other files in there also?

So I'm more wondering whether because the website has been deployed using the Sun Java Application Server, that I can just drop in a new read.jar and restart the server, or is it much more complicated than that?

Cheers,
Rich
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Find out what version of the JRE is being used by the application server. You must then compile your jar with that version set as source and target versions in your compiler settings.
Instead of compiling the jar using Netbeans, consider using a build tool like maven so that your build strategy is not dependent on any IDE.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4699
    
    7

Yikes is right, but I'm talking about what you're trying to do. Depending on the extent of your change, it might not be enough to recompile one Java source file. Ideally, you should have a proper automated build using Gradle, Maven, Ant, etc., for this since your deployment artifact is an EAR file. You should also have your source in a version control system like Git or Subversion.

Assuming the best case where the change requires only recompiling one Java source file, it is possible that what you want to do could work but I wouldn't recommend it. BTW, technically, you don't "compile" a JAR file. Java source files get compiled and the result is a .class file. A JAR file can be created and .class files can be added to it. Likewise, an EAR file can be created and JAR files added to it.

Best case scenario (if you really want to do it this way):
1. Change .java file (source)
2. Recompile (after committing changes to version control, if you have it)
3. Update the JAR file with the .class file from Step 2
4. Update the EAR file with the JAR file in Step 3
5. Redeploy the EAR file
6. Restart your application

Again, I recommend just doing a full build after editing your Java source file.


Junilu - [How to Ask Questions] [How to Answer Questions]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Rich Bantges wrote:All I'd like to do is edit one of the .java files that makes up one of the .jar packages (let's call it read.jar), and the java file read_source.java

Hate to say, but this sounds awfully like a "solution". Have you worked out that what you think needs to be done can't be done with available utilities?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Rich Bantges
Greenhorn

Joined: Jul 17, 2012
Posts: 4
Junilu Lacar wrote:Yikes is right, but I'm talking about what you're trying to do. Depending on the extent of your change, it might not be enough to recompile one Java source file. Ideally, you should have a proper automated build using Gradle, Maven, Ant, etc., for this since your deployment artifact is an EAR file. You should also have your source in a version control system like Git or Subversion.

Assuming the best case where the change requires only recompiling one Java source file, it is possible that what you want to do could work but I wouldn't recommend it. BTW, technically, you don't "compile" a JAR file. Java source files get compiled and the result is a .class file. A JAR file can be created and .class files can be added to it. Likewise, an EAR file can be created and JAR files added to it.

Best case scenario (if you really want to do it this way):
1. Change .java file (source)
2. Recompile (after committing changes to version control, if you have it)
3. Update the JAR file with the .class file from Step 2
4. Update the EAR file with the JAR file in Step 3
5. Redeploy the EAR file
6. Restart your application

Again, I recommend just doing a full build after editing your Java source file.


Thanks for the info and step-by-step guide. The change I want to make is VERY simple:
- I need to edit read_source.java so that it reads a text file "text2.txt" instead of "text.txt"
- I've built the read.jar file (using the build option from Netbeans) - which appears to have worked ok
- I've edited the source format to be JDK5 and the encoding to UTF-8 which appears to match that used on the SOLARIS system
- I've moved the original read.jar and replaced it with my new read.jar and it appears to work (or at least the Appserver restarts ok)

However, I've noticed that in the website-WebModule_war/WEB-INF/classes/website/readproject/ directory, the old .class and text.txt files remain.
Should I manually remove these and replace them with the .class files that were built from the Netbeans?

I'm assuming there's no easy way to discover and re-create the .ear file..

Sorry - it's been a long day, and I'm probably making less sense now that earlier!

Cheers,
Rich
Rich Bantges
Greenhorn

Joined: Jul 17, 2012
Posts: 4
E Armitage wrote:Find out what version of the JRE is being used by the application server. You must then compile your jar with that version set as source and target versions in your compiler settings.
Instead of compiling the jar using Netbeans, consider using a build tool like maven so that your build strategy is not dependent on any IDE.


Thanks - this helped me discover I needed UTF-8 encoding and JDK5.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Yikes - Java .ear .jar .class