First, the assassination did not itself necessarily lead to the war: rather, in the ancient tradition of war-mongering, it provided the pretext for Austria-Hungary to deliver a humiliating and unacceptable ultimatum to Serbia:
The Causes of World War One
... Austria-Hungary's reaction to the death of their heir (who was in any case not greatly beloved by the Emperor, Franz Josef, or his government) was three weeks in coming. Arguing that the Serbian government was implicated in the machinations of the Black Hand (whether she was or not remains unclear, but it appears unlikely), the Austro-Hungarians opted to take the opportunity to stamp its authority upon the Serbians, crushing the nationalist movement there and cementing Austria-Hungary's influence in the Balkans.
It did so by issuing an ultimatum to Serbia which, in the extent of its demand that the assassins be brought to justice effectively nullified Serbia's sovereignty. Sir Edward Grey, the British Foreign Secretary, was moved to comment that he had "never before seen one State address to another independent State a document of so formidable a character" ...
http://www.firstworldwar.com/origins/causes.htm The dangers of Balkan nationalism and Austria-Hungary's designs on Serbia had been noted by a number of observers with concern several years prior to 1918:
Manifesto of the International Socialist Congress at Basel <1912>
... If the Balkan crisis, which has already caused such terrible disasters, should spread further, it would become the most frightful danger to civilization and the proletariat. At the same time it would be the greatest outrage in all history because of the crying discrepancy between the immensity of the catastrophe and the insignificance of the interests involved ...
The Social-Democratic parties of the Balkan peninsula have a difficult task. The Great Powers of Europe, by the systematic frustration of all reforms, have contributed to the creation of unbearable economic, national and political conditions in Turkey which necessarily had to lead to revolt and war. Against the exploitation of these conditions in the interest of the dynasties and the bourgeois classes, the Social-Democratic parties of the Balkans, with heroic courage, have raised the demand for a democratic federation. The Congress calls upon them to persevere in their admirable attitude; it expects that the Social-Democracy of the Balkans will do everything after the war to prevent the results of the Balkan War attained at the price of such terrible sacrifices from being misused for their own purposes by dynasties, by militarism, by the bourgeoisie of the Balkan states greedy for expansion. The Congress, however, calls upon the Socialists of the Balkans particularly to resist not only the renewal of the old enmities between Serbs, Bulgars, Rumanians, and Greeks, but also every violation of the Balkan peoples now in the opposite camp, the Turks and the Albanians. It is the duty of the Socialists of the Balkans, therefore, to fight against every violation of the rights of these people and to proclaim the fraternity of all Balkans peoples including the Albanians, the Turks, and the Rumanians, against the unleashed national chauvinism.
It is the duty of the Social-Democratic parties of Austria, Hungary, Croatia and Slavonia, Bosnia and Herzegovina to continue with all their power their effective action against an attack upon Serbia by the Danubian monarchy. It is their task to continue as in the past to oppose the plan of robbing Serbia of the results of the war by armed force, of transforming it into an Austrian colony, and of involving the peoples of Austria-Hungary proper and together with them all nations of Europe in the greatest dangers for the sake of dynastic interests. In the future the Social-Democratic parties of Austria-Hungary will also fight in order that those sections of the South-Slavic people ruled by the House of Hapsburg may obtain the right to govern themselves democratically within the boundaries of the Austro-Hungarian monarchy proper ...
http://www.marxists.org/history/international/social-democracy/1912/basel-manifesto.htm Serbia's rejection of the July ultimatum, as described in the first link, served as a pretext for Austria-Hungary to declare war on Serbia, as a result of which various treaties came into play. But the actual dynamics of this, in the weeks preceding widespread outbreak of war, required an absolute failure of diplomacy on all sides, as illustrated (for example) by the telegrams between Kaiser Willy and Czar Nicky, which are actual rather representative of the correspondence between the various royalty of Europe:
That the various parties of Europe were able to bring terrible arms to War so immediately was the result of a long and continuing arms race in Europe:
The Land Arms Race and World War I
Gilbert, Martin. A History of the Twentieth Century. Volume One: 1900-1933. New York: William Morrow, 1997.
Herrmann, David G. The Arming of Europe and the Making of the First World War. Princeton, NJ: Princeton University Press, 1996.
Stevenson, David. Armaments and the Coming of the War. Europe, 1904-1914. New York and Oxford: Clarendon Press, 1996.
What was the military context in Europe before World War I? Scholars have traditionally answered this question by emphasizing that the naval competition was essential to the heightened tensions in pre-war Europe. However, some recent historical works strongly question approaches that rank this naval arms competition higher than the lands arms race. Although the naval situation was of concern to the European politicians and public, they argue political leaders considered the army as the dominant force in any upcoming continental conflict ...
http://www.lib.unb.ca/Texts/JCS/FALL98/mctague.htmThis arms race, like the Balkan situation, had already been noted with concern by some observers:
Resolution adopted at the Seventh International Socialist Congress at Stuttgart <1907>
... Wars between capitalist states are, as a rule, the outcome of their competition on the world market, for each state seeks not only to secure its existing markets, but also to conquer new ones. In this, the subjugation of foreign peoples and countries plays a prominent role. These wars result furthermore from the incessant race for armaments by militarism, one of the chief instruments of bourgeois class rule and of the economic and political subjugation of the working class.
Wars are favored by the national prejudices which are systematically cultivated among civilized peoples in the interest of the ruling classes for the purpose of distracting the proletarian masses from their own class tasks as well as from their duties of international solidarity ...
The Congress, therefore, considers it as the duty of the working class and particularly of its representatives in the parliaments to combat the naval and military armaments with all their might, characterizing the class nature of bourgeois society and the motive for the maintenance of national antagonisms, and to refuse the means for these armaments. It is their duty to work for the education of the working-class youth in the spirit of the brotherhood of nations and of Socialism while developing their class consciousness.
The Congress sees in the democratic organization of the army, in the substitution of the militia for the standing army, an essential guarantee that offensive wars will be rendered impossible and the overcoming of national antagonisms facilitated ...
http://www.marxists.org/history/international/social-democracy/1907/militarism.htm Local militarism, economic interests, and nationalist sentiments did not merely prevent any effective diplomatic effort by the royal European heads of state to forestall all-out war; the same forces also catastrophically split the Second International. All the fine-sounding internationalist and anti-militarist rhetoric was swept away by the conflicting individual patriotic impulses of various representatives from different countries
One wants to ask
Could an effective early 20th century international movement against the European arms race, for reorganization of the European military forces as democratized militias rather than undemocratic standing armies, and against extreme nationalistic sentiments have prevented the Great War? -- but of course that is merely an unanswerable philosophical question
<edit:format correction>