I have some .java files and the unzipped tomcat folder and I have to build a single "install.sh" file to add the site to tomcat.
What I would do is:
create a dir in tomcat/webapps/myapp
copy the index.html file
But how do I install the .java files?
Note: this has to be highly portable, so I cannot rely on mvn or some other terminal tools.
After the ./install.sh I want to be able to run "bin/catalina.sh" and browse to localhost/myapp
Is this possible?
I hope this could help you.
You need to have the tomcat and jdk:
1) You can create the jar file using:
jar cvf TicTacToe.jar TicTacToe.class audio images
(You can see more here https://docs.oracle.com/javase/tutorial/deployment/jar/build.html)
2) Then, you just enter to tomcat's bin folder and do startup.sh
If you need to change some class after that, you can compile the classes you need and replace them in WEB-INF/classes folder inside webapps.
I hope this can help you.
Related
i have a folder on my desktop named theme.I am new to Linux totally.
So what do I do to create a jar file from this folder?
I found this example but It doesn't work for me.
jar -cvf theme.jar
You are failing to specify the input files for the jar.
Navigate to the theme/ directory using the cd command in Terminal. If you want to include everything in this directory in your jar file, use the following command.
jar cvf theme *
Note that the * character (wildcard) indicates you want to include all files and subdirectories.
See: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Jar files are really just zip files, renamed to .jar. Just use any folder zipping tool (such as the zip command).
zip -r theme.jar /path/to/desktop/theme
Is it possible to take existing .class files and a MANIFEST.MF to create a jar file?
Is there a library that can create a "valid" jar-file? I tried it manually and it didn't work (using 7zip).
ERROR: "Invalid or corrupt jar file"
If everything has been compiled before, it should (in my understanding) theoretically work, if you create a new zip file, put all the files in it in the original structure and then rename it to "jar".
My idea is to program something like this with java code. A solution where I could add a file to an existing jar, would also be ok.
If you're interested in why I want to use this, look at my initial question: Compile javacode out of a running java accpilaction - on a system that hasn't JDK installed
Well Jar -cf
Try the jar command in $JAVA_HOME/bin
$JAVA_HOME is the path to you JRE/JDK installation
I have been trying to convert jython scripts to .jar file. I followed,
Distributing my Python scripts as JAR files with Jython?
The link above and also the Jython wiki link shown inside it use a command line script called, "zip". Its like => zip myapp.jar Lib
and so. I am on windows machine, so I couldn't find any script as "zip" on my command line, may be its a Linux script. Help me to do it in windows machine
Second is I have few external .jar's that are used in my jython scripts, for this the above link says to use manifest. But I want to package all external jars into single myapp.jar(for example) file to be running. Just like java -jar myapp.jar, so is there any way to package external jars also?
So please help me resolve this
You can use jar command to add files to .jar archive. Just like:
jar uvf jythonlib.jar Lib
Use jar to see help with options and examples of usage.
As you can see, the code zip -r jythonlib.jar Lib and zip myapp.jar Lib/showobjs.py, just add files to a jar archive. The zip program is a specific tool to do this, but it is not the only one. On windows, I would recommend using 7-zip to create the jar. Rather than zip -r jythonlib.jar Lib, open a new 7-zip window, create a new archive (zip protocol) called jythonlib.jar and add the folder called Lib which resides in $JYHTON_HOME. Then continue with the guide and when you get to zip myapp.jar Lib/showobjs.py, simply drag and drop the file called showobjs.py into the existing 7-zip window. This should add the file to the archive.
I'm not very skilled in writing batch files and/ or java. I have a folder with several .class-Files and folders in it and I want to put them all into a executable .jar-File. I know that there is a tool called "jar - The Java Archive Tool", but that just won't work for me. My folder structure looks like this:
Folder "test"
File (a.class)
Folder "subdirectory"
File (b.class)
I want a executable .jar-File called file.jar. In this .jar should now be the file a.class and the folder subdirectory with the file b.class in it.
I don't get the .jar-Tool to run and the 7zip command line doesn't support .jars (I can't even add files to it). I want this to run from a .bat-File, so I just have to open the batch-file, it creates the .jar and puts the files in it and then closes itself again.
I hope you can help me and get what I mean.
If you have issues in executing jar command, then probably you would need to check if your path has been set correctly. You can verify if the path contains jdk location ( echo %path%) from command prompt. If not you need to update. Also you can verify using Javac -verbose command to see jdk is installed.
Once you have jdk path set, you can try below command to create jar
Jar -cf myapp.jar * --> includes all files including files from sub folders.
If you want to run from batch, you would need to mention path before jar command. Ideal place for path is to configure as environment property.
Create a text file (and call it something useful like manifest.txt). In it, put the line:
Main-Class: a
(which should be called A by convention) and include a hard return at the end.
Then create the jar with:
jar cvfm file.jar manifest.txt *.class
or
jar cvfm c:\somedir\file.jar c:\somedir\mainfest.txt *
You could just put that line in a batch file called createJar.bat and run it if you only want to create files called 'file.jar'
hth
I have written a Java program which I package and run from a JAR file. I need to have some user-changeable configuration files which are simply text lines of:
key = value
format. To load these files I used the class described here. When I run my program through Netbeans IDE all works fine as I have included the directory where I store the configuration files in the Project properties.
The problem comes when I build my application into a JAR file. As I want the configuration files to be user-editable I keep them OUTSIDE of the JAR but in the same directory but now when I run my application from the command line it cannot find the configuration files. If I manually add the files to JAR file at the ROOT folder then all is well.
So how can I tell Java to look outside of the JAR for my loadable files? The -classpath option has no effect.
That's because the way you are loading them requires that they be inside the .jar when running from a jar, or inside the project directory if not; it's relying on the classloader to tell it where to find the file.
If you want to open a file outside the .jar, you need to just open it as a File and read it in.
One of the ways we've approached this is to take the external filename as an option on the command line (e.g. java -jar myJar.jar -f filename). This allows you to explicitly state where the file is located. You can then decide whether or not to also look in a default location, or inside the .jar if the file isn't specified on the command line.
I resolved it by referring to this question. I Added the current directory to the MANIFEST file of the jar and it works.
Why is the -classpath option ignored in this case I wonder? Security?
I had the same problem and saw your post, but the answer in the end, was simple.
I have an application deployed via Java Webstart and am building it in Netbeans 7.3.
I have a properties file config.xml that will be updated during run time with user preferences, for instance, "remember my password".
Hence it needs to be external to the jar file.
Netbeans creates a 'dist' folder under the project folder. This folder contains the project jar file and jnlp file. I copied over the config.xml to the dist folder and the properties file was loaded using standard
FileInputStream in = new FileInputStream("config.xml");
testData.loadFromXML(in);
in.close();