package com.marek.Files;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class openFile
{
public static void main(String[] args)
{
try
{
System.out.print("Please Enter file name: ");
String fName;
Scanner scanIn = new Scanner(System.in);
fName = scanIn.nextLine();
BufferedReader br = new BufferedReader(new FileReader(fName));
String sCurrentLine;
try
{
while ((sCurrentLine = br.readLine()) !=null)
{
System.out.println(sCurrentLine);
}
}
finally
{
br.close();
scanIn.close();
}
}
catch (IOException e)
{
//e.printStackTrace();
System.out.println("No such file..");
}
}
}
poniedziałek, 28 kwietnia 2014
how to check if file is empty - Java
File f = new File(fileName);
try
{
if( f.length() == 0 )
{
f.createNewFile();
}
else
{
doSomething()
}
}
catch (IOException e)
{
System.out.println("IO Error: " + e.getMessage());
}
finally
{
enable/disable glass fish app
cd $GLASS_FISH_HOME
for example:
/u01/usr/local/glasshfish3/glassfish/bin
asadmin disable appname
asadmin enable appname
[root@kaukaz bin]# ./asadmin enable SwdDiagnostic
Enter admin user name> admin
Enter admin password for user "admin">
remote failure: Unknown plain text format. A properly formatted response from a PlainTextActionReporter
always starts with one of these 2 strings: PlainTextActionReporterSUCCESS or PlainTextActionReporterFAILURE. The response we received from the server was not understood: Signature-Version: 1.0
message: Exception while preparing the app
Exception [EclipseL
ink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): or
g.eclipse.persistence.exceptions.DatabaseException
Internal Exception
: java.sql.SQLException: Error in allocating a connection. Cause: Con
nection could not be allocated because: ORA-01017: niepoprawna nazwa
uĹytkownika/hasĹo; odmowa zalogowania
[root@kaukaz bin]# ./asadmin enable SwdDiagnostic
Enter admin user name> admin
Enter admin password for user "admin"
Command enable executed successfully
for example:
/u01/usr/local/glasshfish3/glassfish/bin
asadmin disable appname
asadmin enable appname
[root@kaukaz bin]# ./asadmin enable SwdDiagnostic
Enter admin user name> admin
Enter admin password for user "admin">
remote failure: Unknown plain text format. A properly formatted response from a PlainTextActionReporter
always starts with one of these 2 strings: PlainTextActionReporterSUCCESS or PlainTextActionReporterFAILURE. The response we received from the server was not understood: Signature-Version: 1.0
message: Exception while preparing the app
Exception [EclipseL
ink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): or
g.eclipse.persistence.exceptions.DatabaseException
Internal Exception
: java.sql.SQLException: Error in allocating a connection. Cause: Con
nection could not be allocated because: ORA-01017: niepoprawna nazwa
uĹytkownika/hasĹo; odmowa zalogowania
[root@kaukaz bin]# ./asadmin enable SwdDiagnostic
Enter admin user name> admin
Enter admin password for user "admin"
Command enable executed successfully
wtorek, 22 kwietnia 2014
oracle-xe ubuntu starting problem
problem:
root@lati:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin# ./oracle_env.sh
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 108: /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: [[: not found
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 110: /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: [[: not found
root@lati:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin# ./nls_lang.sh
./nls_lang.sh: 108: ./nls_lang.sh: [[: not found
./nls_lang.sh: 110: ./nls_lang.sh: [[: not found
solution:
in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh
change:
#!/bin/sh
to
#!/bin/bash
root@lati:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin# ./oracle_env.sh
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 108: /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: [[: not found
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 110: /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: [[: not found
root@lati:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin# ./nls_lang.sh
./nls_lang.sh: 108: ./nls_lang.sh: [[: not found
./nls_lang.sh: 110: ./nls_lang.sh: [[: not found
solution:
in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh
change:
#!/bin/sh
to
#!/bin/bash
sed - how to add something in front of line
1. marek@lati:/tmp$ cat test
marek
sed
awk
linux
2. make change only in output
marek@lati:/tmp$ sed 's/^/....../g' test
......marek
......sed
......awk
......linux
3. add few "." in the front of the line and save it to source file
marek@lati:/tmp$ sed -i 's/^/....../g' test
marek@lati:/tmp$ cat test
......marek
......sed
......awk
......linux
marek
sed
awk
linux
2. make change only in output
marek@lati:/tmp$ sed 's/^/....../g' test
......marek
......sed
......awk
......linux
3. add few "." in the front of the line and save it to source file
marek@lati:/tmp$ sed -i 's/^/....../g' test
marek@lati:/tmp$ cat test
......marek
......sed
......awk
......linux
poniedziałek, 14 kwietnia 2014
eclipse problem
problem:
root@lati:~/.eclipse/org.eclipse.platform_3.7.0_155965261/configuration# cat 1397493884904.log
!SESSION 2014-04-14 18:44:44.801 -----------------------------------------------
eclipse.buildId=I20110613-1736
java.version=1.7.0_51
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=pl_PL
Command-line arguments: -os linux -ws gtk -arch x86_64
!ENTRY org.eclipse.osgi 4 0 2014-04-14 18:44:49.097
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-gtk-3740 in java.library.path
no swt-gtk in java.library.path
Can't load library: /home/marek/.swt/lib/linux/x86_64/libswt-gtk-3740.so
Can't load library: /home/marek/.swt/lib/linux/x86_64/libswt-gtk.so
solution:
Ubuntu 12.04 32 bit. I edit the command to:
root@lati:~/.eclipse/org.eclipse.platform_3.7.0_155965261/configuration# cat 1397493884904.log
!SESSION 2014-04-14 18:44:44.801 -----------------------------------------------
eclipse.buildId=I20110613-1736
java.version=1.7.0_51
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=pl_PL
Command-line arguments: -os linux -ws gtk -arch x86_64
!ENTRY org.eclipse.osgi 4 0 2014-04-14 18:44:49.097
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-gtk-3740 in java.library.path
no swt-gtk in java.library.path
Can't load library: /home/marek/.swt/lib/linux/x86_64/libswt-gtk-3740.so
Can't load library: /home/marek/.swt/lib/linux/x86_64/libswt-gtk.so
solution:
Ubuntu 12.04 32 bit. I edit the command to:
ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86/
And on Ubuntu 12.04 64 bit try: ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/
niedziela, 13 kwietnia 2014
install jdk mint linux
1. sudo apt-get update && apt-get remove openjdk*
2. download newest version from oracle.com
3. "unzip" jdk archive tar -zxvf jdk-
4. sudo mkdir -p /opt/java
5. sudo mv jdk1.7.0_25 /opt/java
6. sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_25/bin/java" 1
sudo update-alternatives --set java /opt/java/jdk1.7.0_25/bin/java
2. download newest version from oracle.com
3. "unzip" jdk archive tar -zxvf jdk-
4. sudo mkdir -p /opt/java
5. sudo mv jdk1.7.0_25 /opt/java
6. sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_25/bin/java" 1
sudo update-alternatives --set java /opt/java/jdk1.7.0_25/bin/java
how to enable autologin in weblogic
goto:
for example
/home/marek/as/weblogic/wl/user_projects/domains/mbo/servers/AdminServer
make dir: security
cd sercurity
vi boot.properties
username=weblogic
password=password1234
after first start inside of this file we find:
<2014-04-13 11:20:49 CEST> <Notice> <Security> <BEA-090083> <Storing boot identity in the file: /home/marek/as/weblogic/wl/user_projects/domains/mbo/servers/AdminServer/security/boot.properties.>
[marek@localhost security]$ cat boot.properties
#Sun Apr 13 11:20:49 CEST 2014
password={AES}Ka1REcyH2XCTR04sH1231231231231231231231pQ\=
username={AES}5YSNvhM7R+j5RFRuXuKHoTZawFEjxCip1h4yytjzI9k\
for example
/home/marek/as/weblogic/wl/user_projects/domains/mbo/servers/AdminServer
make dir: security
cd sercurity
vi boot.properties
username=weblogic
password=password1234
after first start inside of this file we find:
<2014-04-13 11:20:49 CEST> <Notice> <Security> <BEA-090083> <Storing boot identity in the file: /home/marek/as/weblogic/wl/user_projects/domains/mbo/servers/AdminServer/security/boot.properties.>
[marek@localhost security]$ cat boot.properties
#Sun Apr 13 11:20:49 CEST 2014
password={AES}Ka1REcyH2XCTR04sH1231231231231231231231pQ\=
username={AES}5YSNvhM7R+j5RFRuXuKHoTZawFEjxCip1h4yytjzI9k\
sobota, 12 kwietnia 2014
add repository/source to eclipse
Scala source
1. Open Eclipse
2. Click Help / Install New Software
3. Click add and enter:
http://download.scala-ide.org/sdk/helium/e38/scala210/stable/site
Eclipse start whole process and after that process you need to restart the IDE
1. Open Eclipse
2. Click Help / Install New Software
3. Click add and enter:
http://download.scala-ide.org/sdk/helium/e38/scala210/stable/site
Eclipse start whole process and after that process you need to restart the IDE
files from rpm package
How Do I List Files For Installed Package?
You need to use rpm command as follows:[marek@localhost Pobrane]$ rpm -ql sqldeveloper
alernative
rpm -qlp sqldeveloper-4.0.1.14.48-1.noarch.rpm
Remi repo fedora
## Fedora 20 ## rpm -Uvh http://rpms.famillecollet.com/remi-release-20.rpm ## Fedora 19 ## rpm -Uvh http://rpms.famillecollet.com/remi-release-19.rpm ## Fedora 18 ## rpm -Uvh http://rpms.famillecollet.com/remi-release-18.rpm ## Fedora 17 ## rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm
yum must remember to enable remi repo in:
[marek@localhost ~]$ cat /etc/yum.repos.d/remi.repo [remi] name=Les RPM de remi pour Fedora $releasever - $basearch #baseurl=http://rpms.famillecollet.com/fedora/$releasever/remi/$basearch/ mirrorlist=http://rpms.famillecollet.com/fedora/$releasever/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
piątek, 11 kwietnia 2014
discover active hosts in network
[marek@localhost Dokumenty]$ nmap -sP 192.168.0.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2014-04-11 22:30 CEST
Nmap scan report for 192.168.0.1
Host is up (0.0064s latency).
Nmap scan report for 192.168.0.10
Host is up (0.0095s latency).
Nmap scan report for 192.168.0.11
Host is up (0.000091s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.94 seconds
Starting Nmap 6.40 ( http://nmap.org ) at 2014-04-11 22:30 CEST
Nmap scan report for 192.168.0.1
Host is up (0.0064s latency).
Nmap scan report for 192.168.0.10
Host is up (0.0095s latency).
Nmap scan report for 192.168.0.11
Host is up (0.000091s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.94 seconds
czwartek, 10 kwietnia 2014
Fedora 20 flash player instalation
1.
su -c 'yum -y install http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm'
2.rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
3.yum -y install flash-plugin
file name change script
#!/usr/bin/bash
for i in UI*.java
do
new="G${i}"
echo $i ' ==> ' $new
mv $i $new
done
for i in UI*.java
do
new="G${i}"
echo $i ' ==> ' $new
mv $i $new
done
poniedziałek, 7 kwietnia 2014
jsp connected to oracle-xe instance
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Oracle Connection</TITLE>
</HEAD>
<BODY>
<%
Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "login", "pass");
out.println("connected....!!");
}
catch(Exception e)
{
out.println("Exception : " + e.getMessage() + "");
}
%>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Oracle Connection</TITLE>
</HEAD>
<BODY>
<%
Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "login", "pass");
out.println("connected....!!");
}
catch(Exception e)
{
out.println("Exception : " + e.getMessage() + "");
}
%>
</BODY>
</HTML>
create DB user with admin rights
CREATE USER username IDENTIFIED BY password;
then separately grant privileges with ADMIN OPTION;GRANT dba TO username WITH ADMIN OPTION;
SQL> alter user marek identified by pass;
User altered.
how to make heap dump
how to make gc heap dump
1. [marek@localhost bin]$ jcmd 8560 GC.heap_dump /tmp/test1.dump
8560:
Heap dump file created
2. Read file
[marek@localhost bin]$ jhat -port 7777 -J-mx4G /tmp/test1.dump
Reading from /tmp/test.dump...
Dump file created Mon Apr 07 15:04:00 CEST 2014
Snapshot read, resolving...
Resolving 819250 objects...
Chasing references, expect 163 dots...................................................................................................................................................................
Eliminating duplicate references...................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7777
Server is ready.
1. [marek@localhost bin]$ jcmd 8560 GC.heap_dump /tmp/test1.dump
8560:
Heap dump file created
2. Read file
[marek@localhost bin]$ jhat -port 7777 -J-mx4G /tmp/test1.dump
Reading from /tmp/test.dump...
Dump file created Mon Apr 07 15:04:00 CEST 2014
Snapshot read, resolving...
Resolving 819250 objects...
Chasing references, expect 163 dots...................................................................................................................................................................
Eliminating duplicate references...................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7777
Server is ready.
jcmd - very usefull tool
jcmd - new diagnistic tool from jdk 7 package. Very usefool in all jvm administration processes.
very small example:
1. man jcmd
2. jcmd - process list
3. available options to run
[marek@localhost mb]$ jcmd 7607 help
7607:
The following commands are available:
VM.native_memory
VM.commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
Thread.print
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
.....
[marek@localhost mb]$ jcmd 8560 PerfCounter.print | grep java.property.java.vm
java.property.java.vm.info="mixed mode"
java.property.java.vm.name="Java HotSpot(TM) 64-Bit Server VM"
java.property.java.vm.specification.name="Java Virtual Machine Specification"
java.property.java.vm.specification.vendor="Oracle Corporation"
java.property.java.vm.specification.version="1.7"
java.property.java.vm.vendor="Oracle Corporation"
java.property.java.vm.version="24.51-b03"
very small example:
1. man jcmd
2. jcmd - process list
3. available options to run
[marek@localhost mb]$ jcmd 7607 help
7607:
The following commands are available:
VM.native_memory
VM.commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
Thread.print
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
.....
[marek@localhost mb]$ jcmd 8560 PerfCounter.print | grep java.property.java.vm
java.property.java.vm.info="mixed mode"
java.property.java.vm.name="Java HotSpot(TM) 64-Bit Server VM"
java.property.java.vm.specification.name="Java Virtual Machine Specification"
java.property.java.vm.specification.vendor="Oracle Corporation"
java.property.java.vm.specification.version="1.7"
java.property.java.vm.vendor="Oracle Corporation"
java.property.java.vm.version="24.51-b03"
Subskrybuj:
Posty (Atom)