Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD
PHP & SGBD Forum d'entraide sur les SGBD avec PHP. Avant de poster : FAQ BDD, toutes les FAQ PHP, cours BDD et sources BDD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/07/2011, 18h57   #1
Membre du Club
 
Homme
Analyse système
Inscription : mars 2011
Messages : 406
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Analyse système

Informations forums :
Inscription : mars 2011
Messages : 406
Points : 67
Points : 67
Par défaut jasper report PHP

Bonjour,
Bonjour,
je travaille avec php sous wamp et je veux faire appelle a mon jrxml voila j'ai :
1.installer tomcat biensur et le jdk
2.j'ai configurer mon PHP.ini(c:/wamp/bin/php/php5.2.6):
Code :
1
2
3
4
5
6
7
8
[java]
java.java_home = "c:\Program File\Java\jdk1.6.0_24\bin"
java.java = "c:\Program File\Java\jdk1.6.0_24\bin\javaw.exe"
java.class.path = "c:\wamp\bin\php\php5.2.6\ext\JavaBridge.jar"
java.library.path = "c:\wamp\bin\php\php5.2.6\ext"
;java.hosts = "127.0.0.1:8080"
;java.servlet = On
java.log_level = 2
et j'ai ajouter le javabridge.jar dans le répertoire(C:\wamp\bin\php\php5.2.6\ext)

3.j'ai lancé wamp et tomcat.et j'arrive pas a afficher les info de java (pj)via
Images attachées
Type de fichier : jpg face.JPG (2,5 Ko, 16 affichages)
benhsaien est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 12h33   #2
Membre du Club
 
Homme
Analyse système
Inscription : mars 2011
Messages : 406
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Analyse système

Informations forums :
Inscription : mars 2011
Messages : 406
Points : 67
Points : 67
Bonjour,
j'ai pu faire la relation entre php et java mais lors de l'apelle de jrxml j'ai l'erreur suivent :
Code :
Warning: java_require() not supported anymore. Please use
le code est:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php 
require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc");
        $reportsPath ="etat/";
		$reportFileName = "CommandesClients1";
		$jasperReportsLib = "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/WEB-INF/lib/";
		//$jasperReportsLib = "C:/Program Files/Java/jre6/lib/ext";
 
        $handle = @opendir($jasperReportsLib);
while(($new_item = readdir($handle))!==false) {
 
                $java_library_path = 'file:'.$jasperReportsLib.'/'.$new_item.';';
              // echo ' file ===>'.$java_library_path.'<BR>';
            }
            try {
                // chargement des librairies au classpath 
                java_require($java_library_path);
 
                // création de la connexion JDBC 
                $Conn = new Java("org.altic.jasperReports.JdbcConnection");
                // driver        
                $Conn->setDriver("com.mysql.jdbc.Driver");
                // url de connexion
                $Conn->setConnectString("jdbc:mysql://localhost/db");
                // utilisateur
                $Conn->setUser("root");
                // mot de passe
                $Conn->setPassword("user");
 
                // Compilation du fichier JRXML en fichier Jasper        
                $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
                $report = $sJcm->compileReport($reportsPath ."test_etat.jrxml");
 
                // Remplir le modèle avec les données        
                $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
                $print = $sJfm->fillReport(        
                $report, 
                new Java("java.util.HashMap"),
                $Conn->getConnection()
                );
 
                // Export du fichier au format pdf
                $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
                $sJem->exportReportToPdfFile($print, $reportsPath .$reportFileName.".pdf");
 
                if (file_exists($reportsPath .$reportFileName.".pdf")){
                     header('Content-disposition: attachment; filename="'.$reportFileName.'.pdf"');
                     header('Content-Type: application/pdf');
                     header('Content-Transfer-Encoding: binary');
                     header('Content-Length: '. @filesize($reportsPath . $reportFileName.".pdf"));
                     header('Pragma: no-cache');
                     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                     header('Expires: 0');
                     set_time_limit(0);
                     @readfile($reportsPath .$reportFileName.".pdf") or die("problem occurs.");
                 }
 
            } catch (JavaException $ex) {
                 $trace = new Java("java.io.ByteArrayOutputStream");
                $ex->printStackTrace(new Java("java.io.PrintStream", $trace));
                print "java stack trace: $trace\n";
            }    
        ?>
benhsaien est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/08/2011, 12h18   #3
Membre du Club
 
Homme
Analyse système
Inscription : mars 2011
Messages : 406
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Analyse système

Informations forums :
Inscription : mars 2011
Messages : 406
Points : 67
Points : 67
solution est (je parle de mon envirenement):

1. jdk1.6.0_16 tomcat6 wamp2.0(PHP5.2.6) JavaBridgeTemplate5442

2. décomprésser le JavaBridgeTemplate5442.rar et copier JavaBridge.war dans le dossier webapps dans tomcat.

3.créé un dossier dans le webapps nomé JavaBridge et décompreser le javabridge.war avec l'outil ALZIP ou winrar.

4.vous allé trouvé un dossier nomé WEB-INF qui comporte un dossier Lib coller ici les librairie de jasperReport.

5.configurer php.ini(c:/wamp/www/bin/php/php5.2.6/):
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
;extension=php_xmlrpc.dll
extension=php_xsl.dll
;extension=php_zip.dll
extension=php_java.dll
 
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
 
[java]
java.java_home = "c:\Program File\Java\jdk1.6.0_16\bin"
java.java = "c:\Program File\Java\jdk1.6.0_16\bin\javaw.exe"
java.class.path = "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\JavaBridge\WEB-INF\lib\JavaBridge.jar"
java.library.path = "c:\wamp\bin\php\php5.2.6\ext"
;java.hosts = "127.0.0.1:8080"
;java.servlet = On
java.log_level = 2
inicialiser avec les version de votre envirenement.

6.puis configurer les variable d'envirenement :http://www.dsl.uow.edu.au/~sk33/php5java.htm

7. redémarer tomcat et wamp

8.premier intéraction entre php et java(wamp/www/test.php):
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php 
require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc");
	$system = new Java('java.lang.System');
 
	// accéder aux propriétés
	echo 'Java version=' . $system->getProperty('java.version') . ' <br />';
	echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br />';
	echo 'OS=' . $system->getProperty('os.name') . ' ' .
		     $system->getProperty('os.version') . ' on ' .
		     $system->getProperty('os.arch') . '<br />';
 
	// Exemple avec java.util.Date
	$formater = new Java('java.text.SimpleDateFormat',
			      "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
 
	echo $formater->format(new Java('java.util.Date'));
	?>
resultas est :
Code :
1
2
3
4
Java version=1.6.0_16 
Java vendor=Sun Microsystems Inc.
OS=Windows XP 5.1 on x86
vendredi, août 05, 2011 at 9:46:57 AM Heure d'Europe de l'Ouest
9. l'appelle au fichier jrxml depuis php:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?PHP
 
function checkJavaExtension()
{
    if(!extension_loaded('java'))
    {
        $sapi_type = php_sapi_name();
        $port = (isset($_SERVER['SERVER_PORT']) && (($_SERVER['SERVER_PORT'])>1024)) ? $_SERVER['SERVER_PORT'] : '8080';
        if ($sapi_type == "cgi" || $sapi_type == "cgi-fcgi" || $sapi_type == "cli") 
        {
            if(!(PHP_SHLIB_SUFFIX=="so" && @dl('java.so'))&&!(PHP_SHLIB_SUFFIX=="dll" && @dl('php_java.dll'))&&!(@include_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc"))&&!(require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc"))) 
            {
                return "java extension not installed.";
            }
        } 
        else
        {
            if(!(@include_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc")))
            {
                require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc");
            }
        }
    }
    if(!function_exists("java_get_server_name")) 
    {
        return "The loaded java extension is not the PHP/Java Bridge";
    }
 
    return true;
}
 
/** 
 * convert a php value to a java one... 
 * @param string $value 
 * @param string $className 
 * @returns boolean success 
 */  
function convertValue($value, $className)  
{  
    // if we are a string, just use the normal conversion  
    // methods from the java extension...  
    try   
    {  
        if ($className == 'java.lang.String')  
        {  
            $temp = new Java('java.lang.String', $value);  
            return $temp;  
        }  
        else if ($className == 'java.lang.Boolean' ||  
            $className == 'java.lang.Integer' ||  
            $className == 'java.lang.Long' ||  
            $className == 'java.lang.Short' ||  
            $className == 'java.lang.Double' ||  
            $className == 'java.math.BigDecimal')  
        {  
            $temp = new Java($className, $value);  
            return $temp;  
        }  
        else if ($className == 'java.sql.Timestamp' ||  
            $className == 'java.sql.Time')  
        {  
            $temp = new Java($className);  
            $javaObject = $temp->valueOf($value);  
            return $javaObject;  
        }  
    }  
    catch (Exception $err)  
    {  
        echo (  'unable to convert value, ' . $value .  
                ' could not be converted to ' . $className);  
        return false;  
    }
 
    echo (  'unable to convert value, class name '.$className.  
            ' not recognised');  
    return false;  
}
 
 
checkJavaExtension();
 
 
 
 
				$objClass = new Java("java.lang.Class");
$objClass->forName('com.mysql.jdbc.Driver');
$objDbm = new Java("java.sql.DriverManager");
$objconn = $objDbm->getConnection("jdbc:mysql://localhost/gestion_missions","root","");
 
 
 
 
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");  
$report = $compileManager->compileReport(realpath("etat/test_etat.jrxml"));  
 
$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");  
 
$params = new Java("java.util.HashMap");  
$params->put("a", 70);
$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");  
$jasperPrint = $fillManager->fillReport($report, $params, $objconn);  
 
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");  
 
$outputPath = realpath(".")."/"."output.pdf";
 
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
 
header("Content-type: application/pdf");
readfile($outputPath);
 
unlink($outputPath);
 
 
 
 header('Content-disposition: attachment; filename="'."output.pdf".'.pdf"');
				     header('Content-Type: application/pdf');
				     header('Content-Transfer-Encoding: binary');
				     header('Content-Length: '. @filesize("". "output.pdf".".pdf"));
				     header('Pragma: no-cache');
				     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
				     header('Expires: 0');
				     set_time_limit(0);
				     @readfile($reportsPath .$reportFileName.".pdf") or die("problem occurs.");
des question ???
benhsaien est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/08/2011, 13h30   #4
Membre du Club
 
Homme
Analyse système
Inscription : mars 2011
Messages : 406
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Analyse système

Informations forums :
Inscription : mars 2011
Messages : 406
Points : 67
Points : 67
le probléme qui réste:
le chemain suivent sa fonctionne pas:
Code :
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
Code :
Warning: require_once() [function.require-once]: URL file-access is disabled
par contre :
Code :
require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc");
??
benhsaien est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/08/2011, 21h55   #5
Rédacteur/Modérateur
 
Avatar de Thes32
 
Homme
Développeur Web
Inscription : décembre 2006
Messages : 2 335
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : décembre 2006
Messages : 2 335
Points : 3 774
Points : 3 774
C'est normal l'inclusion par url exécute d'abord le fichier et te renvoi le resultat
__________________
Développeur | Zend Certified Engineer

Étapes Pour mieux se servir du forum:
1. Commencez par lire les cours et tutoriels ;
2. Faites une recherche;
3. Faites un post si rien trouvé dans les deux étapes précédentes en respectant les règles;

Nix>_Rien n'est plus pratique que la théorie
Thes32 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/08/2011, 13h11   #6
Membre du Club
 
Homme
Analyse système
Inscription : mars 2011
Messages : 406
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Analyse système

Informations forums :
Inscription : mars 2011
Messages : 406
Points : 67
Points : 67
et c'est comment ???
benhsaien est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 13h28.


 
 
 
 
Partenaires

Hébergement Web