I'm trying to get the current revision number of the working copy to log it into the log file.
The software is written in Java. So how is it possible to access the revision number through Java?
It's unclear what kind of software you're writing - a webapp in a war? A standalone java program/client packaged in a jar? If you're creating a war or jar file, you can have your build put the SVN info into the META-INF/MANIFEST.MF and your code can read it from there.
use svnkit and use the folloing method:
SVNWCClient.doInfo()
Related
I want to get the version to change the java version automatically.
Because until 1.16 needs java 8 however from 1.17 to launch server needs java 17 etc.
I was tried get manifest and mainclass. and then, get mainclass's major version.
but high version doesn't contain true data in jar. So it cannot get the true version.
I'm sorry for my bad english.
Thank you for reading.
Okay so presuming;
Java application is running in an environment with a bukkit.jar file
You need to retrieve the version of this .jar
If you open a .jar with an archive explorer, like 7zip, you can browse through there..
I went ahead and downloaded craftbukkit-1.19.2.jar and noticed inside of it's META-INF folder is a 'versions.list' file which contains a a single String
a3e1a91200a28b55f64c43b7980830259798984389c782ab8e07364f2e1eb16a *craftbukkit-1.19.2-R0.1-SNAPSHOT.jar
This seems like a good place to start, this String is likely unique in each build.
Otherwise you could access the jar's Manifest and find something in there.
reading MANIFEST.MF file from jar file using JAVA
I'm kinda new to spring and web development as a whole.
My question is:
When you build a spring boot project (using Maven) into jar file and deploy it via Docker, everything is in one jar file. How can you access your resources (css, js, images, html...) if you want to edit something? Like change something in css file or add something to html page. Is it even possible? Or do you have to build a new jar file everytime, when you need to change something (in frontend)? Also, when there are being uploaded some images or other files, where are they stored? This stuff is very confusing for me and i can't find any related books or help at all.
Thanks for help!
when you package any java program it is nothing but a zip file. Based on what kind of package it is, you wither name it as a Jar or War.
Jar == Java archive
War == Web archive
Now, given the fact that jar and war both are essentially a zip archive, it gives you flexibility to extract and modify them just like any other zip file.
On windows, I think softwares like 7zip let you update the jar inline. I have done it multiple times, especially when I wanted to change application.properties alone on cloud machines, and no other code changes were required. In such cases, building the whole jar and transferring it again to cloud machine could be time consuming. So I would just extract the contents, update whatever I want to, and rezip the package.
Here is the commands you can use -
jar xf jar-file
This should extract the files into a directory.
This SO thread will guide you towards creating jar files.
Something like jar cf myJar.jar ** should be enough to generate a jar file IMO, but syntax might vary.
The jar file is actually just a zip file containing all the files and classes of your application, so technically you can change files in it like any other zip archive. Best practice is to build the jar file using Maven or Gradle from source every time you need something changed.
It's good practice to keep the source in version control using Git, and tag each build in the git repository - that way you can easily keep track of changes to the jar file by looking at what's in git at the time of the build.
I have tried unsuccessfully for a few hours now to edit the java files in a jar I am using as a library. I have marked the resource as a content root and as a source root but I am still unable to edit the code in the jars. The project compiles and runs correctly but I need to make an adjustment to a resource file and cannot; I have tried every project structure I could think of. Is it just impossible? All help is appreciated.
It is not recommended to edit JAR files. From the perspective of reproducibility1, it is better to:
Get hold of the source tree for the library
Check it into your version control (or fork it on Github)
Modify and build it
Use the resulting JAR instead of the original JAR
Another approach is to "overlay" the changes you want to make by creating a another JAR with the alternative version of the resources and placing it earlier in the application classpath.
But if neither of those works for you, you can use the jar command from the command line to modify a JAR file:
Use jar -x ... to extract the files to a temporary directory tree
Apply what ever changes need to be made to the tree
Use jar -c .... to create a new JAR from the tree.
Read the manual entry for the jar command for more details. Signing the new JAR with the original keys would be an issue if you are not the original signer, but I doubt that that is relevant to you.
1 - The point is that the next guy maintaining your code needs to know what you did to the library JAR that you "edited", in case he needs to do the same procedure with another version of the JAR. If you do it by hand, he has no choice but to do a forensic comparison of the differences between the original and your edited version. And that assumes that the original JAR can still be obtained. Note that "the next guy" could be you ... in a couple of months or years time, when you have forgotten exactly what you did.
I am following a course work on Apache Storm from Udacity. The version of storm being used is 0.9.3
One of the exercises there is to run a topology which contains a bolt written in Python. Briefly here are the steps followed. For the purpose of this exercise my source directory is src and my package is udacity.storm
Create directory called resources/ under udacity/storm. Place two python scripts there - splitsentence.py and storm.py.
Create a bolt SplitSentence under the package udacity.storm. SplitSentence bolt derives from ShellBolt and implements the IRichBolt interface.
Build the topology using maven. During the process also package the resources/ directory within the JAR file.
Submit the topology to storm using the command storm jar target/mytopology.jar udacity.storm.MyTopology.
The topology loads up and dies immediately and I see the following error on the console
The storm client can only be run from within a release. You appear to
be trying to run the client from a checkout of Storm's source code.
I took a look at the storm.py code and figured out that this would happen if the lib/ directory is not present in the directory from where the python script is executing. After putting in some debug statements I identified that the python script runs from the following location :
/tmp/06380be9-d413-4ae5-b387-fafe3acf3e65/supervisor/stormdist/tweet-word-count-1-1449502750
I navigate to this directory and find that the lib/ folder is absent.
The Storm Multilang page does not give much information that would be helpful for beginners to debug the problem being faced.
Any help to solve this problem is greatly appreciated.
As the error says you try to run within the source code. Just download the binary release https://storm.apache.org/downloads.html and follow the setup instructions https://storm.apache.org/documentation/Setting-up-a-Storm-cluster.html
Afterwards, you can prepare your jar file and submit to the cluster via bin/storm jar yourJarFile.jar (see https://storm.apache.org/documentation/Command-line-client.html)
There is no need (as long as you don't want to work on Storm itself) to download the source code manually. Just include the corresponding jar files from the binary release to your project. If you use maven (and only run in local mode), just include the corresponding maven dependency (see https://storm.apache.org/documentation/Maven.html); there is no need to download the binary release manually for this case.
I got the problem after some fair amount of looking around. Actually, the problem is not within the instructions themselves but because the storm.py file I had included in my resources directory was of an older or incorrect version - I had obtained the URL via a Google search and probably ended up with an incorrect one.
The storm.py to be downloaded is from this Github link. I am now able to run the exercises successfully.
Thank you all for your help. I will ensure that I post this up in Udacity forums so that people are aware of the confusion.
In case anyone else experiences this problem:
I had the same issue. However, I couldn't resolve it by copying storm.py from the binary release to my resources directory.
My initial error was "AttributeError: 'module' object has no attribute 'BasicBolt'"
You can add the correct Maven dependency to your pom.xml which will copy the correct dependencies into your JAR. Add the artifact "multilang-python", groupId "org.apache.storm" with version matching your Storm version, then run the clean and package goals to produce the updated JAR file.
We want to implement a feature like this: when user firstly run the app, app will download a jar file to local PC from a server and load the jar file but when user run the app again, app can distinguish if the content of the jar file in local folder is same as the one on server, if so not download it again just load it from local folder; if not app will download it and update local one (the jar file name on server and on local must be same). Currently one solution I can think out is to use checksum that is app generates the checksum of local jar file then get the checksum of server jar file from the server, check if they are same, if so not download again, if not download and update. Is there a simple way to generate checksum of a jar file? Or is there any other better solution for this feature? Thanks.
Calculating the jar checksum is the same as calculating the checksum of any file. But it looks like you need Java Web Start, which will take care of everything.
Java Web Start is certainly the right way to do it as Bozho says. For a hand-made alternative see What's the best way to add a self-update feature to a Java Swing application?
You can use the Files.getChecksum(file) from Google Guava libraries
If you are building the jar file with maven there is a maven plug-in for generating check-sums of a compiled jar. Maven Plugin Link .
As for the downloaded jar you can locally SAVE ,rather than generate, the jars check sum. Fetch the check-sum from the server and send a request to the it every time you need to check if the jars check sum is changed and if so download the new one.