When learning JavaEE the first time, it’s hard to find a project that you can click the triangle and see the code run like in Java SE. I’ve been finding projects like that and after countless hours, I’ve found one from Okta.
With some modifications, I could get it up and running and also configure debug options for the application.
Running this JAX-RS application is super easy. The first thing is to make sure you have maven and JDK installed. Next, make sure you add maven bin folder to path and create environment variable for JDK home as JAVA_HOME.
Here is what it’s like on my Windows machine:
I also added maven bin to path:
After that, you can simply run the following command in the project’s root:
mvn clean package tomee:run
How to debug the application
Debugging the application is also quite simple. First, stop the application if it’s running. Then run the following command in the project’s root:
mvn clean package tomee:debug
The console should output something like this:
As you can see, the debug process is listening on port 5005.
Then, create a debugging profile like this:
By default, the debugging port is 5005. My IDE (IntelliJ) is smart enough to guess the port and all left is clicking on OK:
Then you can click on the Bug icon to start debugging:
Conclusion
With this starter project, I hope you can start working on Java EE concepts that are new to you (for example, interceptors, JPA…).
Recently, I need to upgrade my English learning app on Android to use multiple servers. Previously, I used two servers already. However, the way I manage media files caused me a lot of headache. So, I decided to switch to DigitalOcean since they have servers around the world and the pricing is good ($5 for 250GB storage and 1TB monthly transfer, which is good).
The initial problem with DigitalOcean spaces
Coming from old-school servers, I thought I can upload the files to DigitalOcean spaces using FTP and access the files directly as I usually used. However, the first problem is you cannot upload to spaces using FTP and the second problem is in order to make a file accessible to public, you need to set it permission to public. If you have one or two files, that wouldn’t be a problem.
I have more than 18,000 files.
The solutions to uploading multiple files
It turned out that DigitalOcean spaces use Amazon s3 technologies. So, in order to upload to spaces, you need to have FileZilla Pro (paid) or CyberDuck(free). I chose FileZilla Pro because it allows you to resume failed transfers while CyberDuck doesn’t allow that (or I couldn’t find where is that option).
The solution to accessing files
As my app used by thousands of people, the media files need to be accessible to all of the users. Actually, it is very easy to generate a public accessible URL for any files (they are called objects) using the aws-android-sdk. In case you need a working sample code, here it is:
public class DigitalOcean implements MediaServer {
private static final String KEY = "YOUR_KEY";
private static final String SECRETS = "YOUR_SECRETS";
private String endpoint, bucketName;
private AmazonS3Client s3Client;
@Override
public String getEndpoint() {
return endpoint;
}
@Override
public String getType() {
return "s3";
}
public DigitalOcean(String endpoint, String bucketName) {
this.bucketName = bucketName;
this.endpoint = endpoint;
AWSCredentials myCredentials = new BasicAWSCredentials(KEY, SECRETS);
s3Client = new AmazonS3Client(myCredentials);
s3Client.setEndpoint(this.endpoint);
}
public String getMediaURL(String objectPath) {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectPath);
URL objectURL = s3Client.generatePresignedUrl(request);
return objectURL.toString();
}
}
As you can see, I created an object to generate URL to any files(objects). For example, here is a sample space url:
The bucket name would be data-sample.
If your file, let call it song.mp3 located at /data-sample/media/song.mp3, the objectPath would be: /media/song.mp3.
If you run the method getMediaURL(), you will get the path to the file that is accessible to your users but you don’t have to mark the file public.
Recently, I have a specific need to combine multiple files into one big file. The task is very simple. However, if I do it manually (combine over 32,000 small text files into one), it may cost me a day, or even more.
How to combine multiple text files into one
So, I decided to make a tool in Java. Its interface is very simple but you can use it right away without much learning. Here is the app’s interface:
As you can see from the interface, there are three buttons and these are the one you need to pay attention to. To start combining your small .txt files, click on the button “Select files to combine”. Here, I’m going to select all of my .txt file (over 32,000 files). For those of you who are curious, these are the books from project Gutenberg.
Now, click on Open.
Next, you need to select the destination file. This is the file that contains all the text from the small files.
You can see that the path to the destination file is displayed in the text field at the left of the select button.
Now, simply click on combine now. The program will go ahead and combine your files into one file. In my case, all over 32,000 files are combined into one and the destination file is over 250MB! That’s a lot for a .txt file. In fact, there are more than 7 million line of text inside that file.
If you are a Java developer, you can check out the repo here on Github here to modify it to your needs. If you are an user, you can download the ready built app here to start combining your .txt files:
If you are like me, I have to deal with text a lot in my work. As a programmer, I need to find and match string. Recently, a friend of mine, who is an accountant gave me a list of books’ titles. Most of them are fine. However, there are some contains strange characters and she wanted to remove such titles.
As you can see in the picture, there titles with @ and Chinese characters. Using filters doesn’t work because there are more than 1000 rows. That was when I said to myself: “I need a tool”.
So, I made one for this specific purpose: “to help my friend remove all the strange characters in her Excel workbook”.
Here is how the tool look like:
As you can see, you can put the original text in the source string box, adjust a few options above and click on filter. The result will be shown in the Result string box:
As you can see that all the rows that contain strange characters are removed.
However, what if you have some special characters that is allowed to appear in the title? No worries! You can put that into the Allowed characters box and separated them by spaces.
For example, It is OK for me to have the character @ in the title, I would put @ into the Allowed characters box. In addition, that title [email protected] contains the character dot (.) so you need to put that into the list of allowed characters too.
Let’s see what we’ll have:
As you can see now, the title with . and @ is accepted.
There are also two checkboxes that allowed you to filter the text further. You can decide to allow numbers or spaces in the title by checking these checkboxes.
As an ESL, I usually wonder: “how many words I need to know to speak English well?”. I read somewhere that you don’t need more than 2,000 words to carry out 99% of daily conversations. 2,000 words don’t seem to be a lot and if I can learn 10 words a day, I can be conversational in any language in just 200 days (less than a year).
So, what if I want to enjoy the novels, books in English, how many words I need to know.
I doubt the number would be a lot more than 2,000 words.
So I made a tool to read all the text in a book (you can select more than one book in .pdf or .txt format) and it will export all the words in that book into a table.
for Wuthering Heights, you need to know 9,456 words.
That’s a lot of words.
The numbers aren’t 100% correct. There are some gibberish such as website address, two letter (like country codes) may get in the list. However, you can roughly estimate that there are 95% of the numbers are real words.
I find that this is a good way to quickly find out new words that I don’t know. I can click on the words to get the definition (if available) on the right.
You can download the program here for free. If you have any suggestion, please let me know.
Are you a dev? Checkout programming tutorials here: datmt.com
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.